欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

php获取post中的json数据的实现方法

程序员文章站 2023-10-17 16:57:30
突然想到了以前接触过flash将图片二进制流传给php,灵机一动用$globals['http_raw_post_data']获取到了。于是就深入的查了一下,原来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 the post content-type is not something php understands (such as text/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");?>