POST /test.php HTTP/1.1
Host: 192.168.1.135:80
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20100225 Firefox/1.0.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 197
Connection: Keep-Alivedata_packet={"head":{"PacketLen":1,"Cmdid":123,"Seqid":7,"ServiceName":"IDIP","SendTime":20110820,"Version":1001,"Authenticate":"1","Result":0,"RetErrMsg":"1"},"body":{"AreaId":1,"OpenId":"123"}}上面是http的请求
test.php中
$data_packet = $_POST['data_packet'];
$req_data = json_decode($data_packet);
然后输出$data_packet 发现字符串异常如下:
锘縶\"head\":{\"PacketLen\":1,\"Cmdid\":123,\"Seqid\":7,\"ServiceName\":\"IDIP\",\"SendTime\":20110820,\"Version\":1001,\"Authenticate\":\"1\",\"Result\":0,\"RetErrMsg\":\"1\"},\"body\":{\"AreaId\":7,\"OpenId\":\"123\"}}
导致后面json的json_decode出错
怎么才能正确获取post中的字符串,data_packet=后面的拿部分,然后转换成json格式
Host: 192.168.1.135:80
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6)
Gecko/20100225 Firefox/1.0.1
Content-Type: application/x-www-form-urlencoded
Content-Length: 197
Connection: Keep-Alivedata_packet={"head":{"PacketLen":1,"Cmdid":123,"Seqid":7,"ServiceName":"IDIP","SendTime":20110820,"Version":1001,"Authenticate":"1","Result":0,"RetErrMsg":"1"},"body":{"AreaId":1,"OpenId":"123"}}上面是http的请求
test.php中
$data_packet = $_POST['data_packet'];
$req_data = json_decode($data_packet);
然后输出$data_packet 发现字符串异常如下:
锘縶\"head\":{\"PacketLen\":1,\"Cmdid\":123,\"Seqid\":7,\"ServiceName\":\"IDIP\",\"SendTime\":20110820,\"Version\":1001,\"Authenticate\":\"1\",\"Result\":0,\"RetErrMsg\":\"1\"},\"body\":{\"AreaId\":7,\"OpenId\":\"123\"}}
导致后面json的json_decode出错
怎么才能正确获取post中的字符串,data_packet=后面的拿部分,然后转换成json格式
贴出结果
可以这样写$data_packet =stripslashes($_POST['data_packet']);