欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php獲取post中的json數(shù)據(jù)的實(shí)現(xiàn)方法

 更新時(shí)間:2011年06月08日 23:13:37   作者:  
最近用到ext與PHP交互,ext把json數(shù)據(jù)post給PHP,但在PHP里面$_post獲取不到,$_REQUEST也獲取不到,但是通過firedebug看到的請求信息確實(shí)是把JSON數(shù)據(jù)post給了PHP,這什么情況
突然想到了以前接觸過flash將圖片二進(jìn)制流傳給php,靈機(jī)一動(dòng)用$GLOBALS['HTTP_RAW_POST_DATA']獲取到了。
于是就深入的查了一下,原來PHP默認(rèn)只識別application/x-www.form-urlencoded標(biāo)準(zhǔn)的數(shù)據(jù)類型,因此,對型如text/xml 或者 soap 或者 application/octet-stream 之類的內(nèi)容無法解析,如果用$_POST數(shù)組來接收就會失??!故保留原型,交給$GLOBALS['HTTP_RAW_POST_DATA'] 來接收。

php的HTTP_RAW_POST_DATA
用Content-Type=text/xml 類型,提交一個(gè)xml文檔內(nèi)容給了php server,要怎么獲得這個(gè)POST數(shù)據(jù)。
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默認(rèn)只識別application/x-www.form-urlencoded標(biāo)準(zhǔn)的數(shù)據(jù)類型,因此,對型如text/xml的內(nèi)容無法解析為$_POST數(shù)組,故保留原型,交給$GLOBALS['HTTP_RAW_POST_DATA'] 來接收。
另外還有一項(xiàng) php://input 也可以實(shí)現(xiàn)此這個(gè)功能
php://input 允許讀取 POST 的原始數(shù)據(jù)。和 $HTTP_RAW_POST_DATA 比起來,它給內(nèi)存帶來的壓力較小,并且不需要任何特殊的 php.ini 設(shè)置。php://input 不能用于 enctype="multipart/form-data"。

應(yīng)用

a.htm
復(fù)制代碼 代碼如下:

<form action="post.php" method="post">
<input type="text" name="user">
<input type="password" name="password">
<input type="submit">
</form>

post.php
復(fù)制代碼 代碼如下:

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

相關(guān)文章

最新評論