php擷取post中的json資料

來源:互聯網
上載者:User

簡介:這是php擷取post中的json資料的詳細頁面,介紹了和php,有關的知識、技巧、經驗,和一些php源碼等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=337677' scrolling='no'>

轉自:http://dianjingjiaoyu.blog.163.com/blog/static/18347920820114194642257/

   最近用到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'] 來接收。

 

轉自:http://7297576.blog.163.com/blog/static/72686442201022981219526/

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

愛J2EE關注Java邁克爾傑克遜視頻站JSON線上工具

http://biancheng.dnbcw.info/php/337677.html pageNo:9

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.