读取原始post数据,这对于从flashxmlsocket获取XML非常有用。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了读取原始post数据,这对于从flashxmlsocket获取XML非常有用。相关的知识,希望对你有一定的参考价值。

Often php can't interpret POST data because it is not form-encoded. This is typical when the post data is XML from API's like Flash's XmlSocket. You can use the following methods to read the POST data directly.
  1. /**
  2.   Using php://input
  3.   -----------------
  4.   Version: 4.3+
  5.  
  6.   Reading [php://input][1] is the preferred method since PHP 4.3.
  7.  
  8.   The Content-Type header of the posted content must _NOT_ be
  9.   application/x-www.form-urlencoded or multipart/form-data.
  10.  
  11.   For XML you can use the Content-Type: text/xml.
  12.  
  13.   [1]: http://us2.php.net/manual/en/wrappers.php.php
  14.   */
  15.  
  16. // Make sure the user is posting
  17. if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
  18. {
  19. // Read the input from stdin
  20. $postText = trim(file_get_contents('php://input'));
  21. }
  22.  
  23. /**
  24.   Using $HTTP_RAW_POST_DATA
  25.   -------------------------
  26.   Version 3.0+
  27.  
  28.   __Note__: Reading php://input is preferred.
  29.  
  30.  
  31.   As with php://input, the Content-Type header of the
  32.   posted content must _NOT_ be application/x-www.form-urlencoded or
  33.   multipart/form-data.
  34.  
  35.   PHP 4.1+
  36.   ~~~~~~~~
  37.   You can also enable [always-populate-raw-post-data][1] in the php.ini to
  38.   have the value always populated reguardless of Content-Type. However
  39.   since this requires config changes it is less portable.
  40.  
  41.   [1]: http://us2.php.net/manual/en/ini.core.php#ini.always-populate-raw-post-data
  42.   */
  43. $postText = $GLOBALS['HTTP_RAW_POST_DATA'];

以上是关于读取原始post数据,这对于从flashxmlsocket获取XML非常有用。的主要内容,如果未能解决你的问题,请参考以下文章

nodejs从POST请求中获取原始正文[重复]

使用 Postman 通过原始 JSON 发送 POST 数据

从android上的wav文件中读取原始数据

使用 Python 串行库处理从串口读取的原始数据?

如何通过post方法从邮递员的原始数据中保存和下载视频文件等文件

spring应用中多次读取http post方法中的流(附源码)