要在PHP 中整体接收POST数据,有两种方法。
注意,要使用以下两种方法,Content-Type不能为multipart/form-data。
方法一:
使用:
1
file_get_contents
(
'php://input'
)
其中,php://input是一个流,可以读取没有处理过的POST数据(即原始数据)。相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini 设置。
方法二:
使用此方法,需要设置php.ini 中的always_populate_raw_post_data值为On。
使用$HTTP_RAW_POST_DATA,包含了POST的原始数据。但这不是一个超全局变量,要在函数中使用它,必须声明为global,或使用$GLOBALS['HTTP_RAW_POST_DATA']代替。
来源:http://blog.csdn.net/iastro/article/details/52442505
最近用到ext与PHP交互,ext把json数据post给PHP,但在PHP里面$_post获取不到,$_REQUEST也获取不到,但是通过firedebug看到的请求信息确实是把JSON数据post给了PHP,这什么情况? 突然想到了以前接触过flash将图片二进制流传给php,灵机一动用$GLOBALS['HTTP_RAW_POST_DATA']获取到了。于是就深入的查了一下,原来PHP默认只识别application/x-www.form-urlencoded标准的数据类型,因此,对型如text/xml或者 soap 或者 application/octet-stream之类的内容无法解析,如果用$_POST数组来接收就会失败!故保留原型,交给$GLOBALS['HTTP_RAW_POST_DATA']来接收。 php的HTTP_RAW_POST_DATA 用Content-Type=text/xml类型,提交一个xml文档内容给了php server,要怎么获得这个POST数据。 The RAW/ uninterpreted HTTP POST information can be accessed with:$GLOBALS['HTTP_RAW_POST_DATA'] This is useful in cases where thepost Content-Type is not something PHP understands (such astext/xml). 由于PHP默认只识别application/x-www.form-urlencoded标准的数据类型,因此,对型如text/xml的内容无法解析为$_POST数组,故保留原型,交给$GLOBALS['HTTP_RAW_POST_DATA']来接收。 另外还有一项php://input 也可以实现此这个功能 php://input允许读取 POST 的原始数据。和 $HTTP_RAW_POST_DATA 比起来,它给内存带来的压力较小,并且不需要任何特殊的php.ini 设置。php://input 不能用于enctype="multipart/form-data"。 应用 a.htm代码如下: <form action="post.php" method="post"> <input type="text" name="user"> <input type="password" name="password"> <input type="submit"> </form> post.php代码如下: <?echo file_get_contents("php://input");?>
来源:http://blog.csdn.net/moqiang02/article/details/22947707
适用于现代 C++ 的 JSON。
最近提交(Master分支:4 个月前 )
f06604fc
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
* :page_facing_up: bump the copyright years
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com>
---------
Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Signed-off-by: Niels Lohmann <niels.lohmann@gmail.com> 22 天前
d23291ba
* add a ci step for Json_Diagnostic_Positions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* Update ci.cmake to address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typo in the comment
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix typos in ci.cmake
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* invoke the new ci step from ubuntu.yml
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* issue4561 - use diagnostic positions for exceptions
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* address review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci check failures for unit-diagnostic-postions.cpp
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* improvements based on review comments
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix const correctness string
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* further refinements based on reviews
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add one more test case for full coverage
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* ci check fix - add const
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* add unit tests for json_diagnostic_postions only
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_diagnostics
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
* fix ci_test_build_documentation check
Signed-off-by: Harinath Nampally <harinath922@gmail.com>
---------
Signed-off-by: Harinath Nampally <harinath922@gmail.com> 22 天前
旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。
加入社区
所有评论(0)