日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

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

 corefashion 2014-12-04
最近用到騰訊微博與PHP交互,騰訊把json數(shù)據(jù)post給PHP(騰訊推送數(shù)據(jù)時(shí),每條數(shù)據(jù)是一個(gè)json格式的數(shù)據(jù)包,作為post的數(shù)據(jù)體(請(qǐng)注意post數(shù)據(jù)體沒(méi)有參數(shù),不是key=value形式,整個(gè)json包就是post的數(shù)據(jù)體)),但在PHP里面$_post獲取不到,$_REQUEST也獲取不到,但是通過(guò)firedebug看到的請(qǐng)求信息確實(shí)是把JSON數(shù)據(jù)post給了PHP,這什么情況

突然想到了以前接觸過(guò)flash將圖片二進(jìn)制流傳給php,靈機(jī)一動(dòng)用$GLOBALS['HTTP_RAW_POST_DATA']獲取到了。
于 是就深入的查了一下,原來(lái)PHP默認(rèn)只識(shí)別application/x-www.form-urlencoded標(biāo)準(zhǔn)的數(shù)據(jù)類型,因此,對(duì)型如text /xml 或者 soap 或者 application/octet-stream 之類的內(nèi)容無(wú)法解析,如果用$_POST數(shù)組來(lái)接收就會(huì)失敗!故保留原型,交給$GLOBALS['HTTP_RAW_POST_DATA'] 來(lái)接收。

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

應(yīng)用
代碼如下:

<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");?> 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買(mǎi)等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多