日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

php 处理raw数据,PHP用HTTP_RAW_POST_DATA来接收post过来的数据

發(fā)布時(shí)間:2023/12/31 63 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 处理raw数据,PHP用HTTP_RAW_POST_DATA来接收post过来的数据 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

用$GLOBALS[‘HTTP_RAW_POST_DATA’]這個(gè)變量就可以接收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”類型的數(shù)據(jù)

例如

if ( $_SERVER[‘REQUEST_METHOD’] === ‘POST’ )

{

// Read the input from stdin

$postText = trim(file_get_contents(‘php://input’));

}

自己用Python寫(xiě)個(gè)客戶端進(jìn)行測(cè)試

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()

總結(jié)

以上是生活随笔為你收集整理的php 处理raw数据,PHP用HTTP_RAW_POST_DATA来接收post过来的数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。