用$GLOBALS[‘HTTP_RAW_POST_DATA’]这个变量就可以接收post raw data了
php配置中,必须启用 always_populate_raw_post_data
always_populate_raw_post_data = On
并且post header中必须 指定 Content-Type 和 Content-Length的值
比如
Content-Type: application/octet-stream
Content-Length: 1097
另外的方法是,使用 php://input , 但 不能处理 enctype=”multipart/form-data”类型的数据
例如
if ( $_SERVER[‘REQUEST_METHOD’] === ‘POST’ )
{
// Read the input from stdin
$postText = trim(file_get_contents(‘php://input’));
}
http://www.codediesel.com/php/reading-raw-post-data-in-php/
自己用Python写个客户端进行测试
import sys import httplib import binascii data = binascii.unhexlify("27130103333536333832") webservice = httplib.HTTP("10.0.2.2") webservice.putrequest("POST", "/service.php") webservice.putheader("Host", "10.0.2.2") webservice.putheader("Content-type", 'application/octet-stream') webservice.putheader("Content-length", str(len(data))) webservice.endheaders() webservice.send(data) statuscode, statusmessage, header = webservice.getreply() print "Response: ", statuscode, statusmessage print "headers: ", header print webservice.getfile().read()