如何在PHP中访问POST数据? [英] How to access POST data in PHP?
本文介绍了如何在PHP中访问POST数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要编写一个PHP页面来接受通过POST请求发送的XML文档,如下所示:
I need to write a PHP page which would accept an XML document sent over a POST request like this:
POST /mypage.php HTTP/1.1
Host: myhost.com
Content-Type: application/xml
Content-Length: ...
<?xml version="1.0" encoding="utf-8"?>
<data>
...
</data>
这不是某些HTML表单中的数据,只是一个普通的XML文档。
This is not data from some HTML form, just a plain XML document.
如何在我的PHP代码中访问此XML?
How can I access this XML in my PHP code?
推荐答案
阅读 php:// input
。例如,您可以使用:
Read from php://input
. For example, you could use:
$rawdata = file_get_contents('php://input');
或
$rootNode = simplexml_load_file('php://input');
替代方案,使用 $ HTTP_RAW_POST_DATA
,也可以 - 但速度较慢,需要PHP配置 always_populate_raw_post_data
。
The alternative, using $HTTP_RAW_POST_DATA
, works, too - but it's slower and needs the PHP configuration always_populate_raw_post_data
.
这篇关于如何在PHP中访问POST数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文