English 中文(简体)
PHP Reads XML 贴在我的PHP网页上
原标题:PHP Reads XML Posted to my PHP Page
  • 时间:2010-08-04 20:22:02
  •  标签:
  • php
  • xml

I have a PHP page that needs to read XML posted to this page. The post will be done by content-type: application/xml(not application/x-www-form-urlencoded).

For example, my page is called test.php, another server will post the XML to this page (test.php). My question is how can I create a code to this test.php page to read the xml posted to it?

<>>>>>

First, thanks a lot for the answers and the time spent to help me. I´ll try to explaing better my problem. I´m creating a Messenger Robot. I´m using a plataform called "botplataform". More information here: http://code.google.com/p/botplatform/wiki/RobotServiceHostedOnWebServer

Basicaly this plataform works like this: I type a message on my instante messager (in this case MSN), the message that I typed is sent to my PHP page by a XML POST. The information of how this plataform do that is this:

"The post request content-type is application/xml(not application/x-www-form-urlencoded). So you should read the entire body as the xml data, you couldn t read any parameters."

我的PHP文档需要“阅读”这一XML,以了解MSN的用户类型。 并且,我回过头来回答向用户寄送 m子的机器人。

我可以向机器人发送一个答案,但我可以读到XML,即机器人发送到我的实验室档案。

If you want to test, just ad mainframe(at)xquad(dot)com(dot)br to your MSN an talk with it. It will only anser "Em manutencao" But it works, the php create a XML and echo it.

感谢抽签,Flávio

问题回答

您可使用$HTTP_RAW_POST_DATA(manualenter/a>或php http://input

http://us.php.net/manual/en/wrappers.php rel=“nofollow noreferer” 手册:

允许你读到原始<代码>POST数据。 它是一种不太丰富的替代物,可替代<代码>。 HTTP_RAW_POST_DATA,不需要任何特别的php.ini指令。 <代码>php http://input 不能在enctype=“multipart/form-data>上查阅。

<>Update: 也许有些例子可能有助于。

页: 1

<?php
  echo file_get_contents( php://input );
?>

采用URL作为指挥线:

curl -d“<xml><stuff>test</stuff></xml>http:// localhost/input.php

甚至确定内容类型:

curl -H "Content-Type: application/xml" -d ...

产出(按预期):<代码><xml><stuff>test</stuff></xml>

但是,如果你试图upload <>/strong> 文档,通常将enctypemultipart/form-data(脚注,而不是content-type)。

样本文件(test.xml):

<xml>
  <stuff>test</stuff>
</xml>

使用URL载荷:

curl -F “name=@test.xml” http:// localhost/input.php

http:// localhost/input.php

两者都不会产生<代码>投入.php。 但是,如果你修改文字,看_$_FILES 阵列(或者,你将处理normal上载到PHP),那么你就拿到内容。

页: 1

<?php
  echo file_get_contents($_FILES[ name ][ tmp_name ]);
?>

A file upload with curl:

http:// localhost/form.php。

将产生<代码>测试.xml的内容。

在这两种方法中,你应当能够处理<代码>POST/code>或其他服务器的文档或数据。

<>二次更新><>/>:<代码>> 申请/xml 再次工作:

curl -F “name=@test.xml” -H “Content-Type: application/xml”





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...