使用php的curl库 发起http请求的时候 有时候远程接口给我们返回的是这样的数据
HTTP/1.1 200 OK
Server: Tengine
Date: Fri, 01 Nov 2019 09:01:31 GMT
Content-Type: application/json; charset=UTF-8
Content-Length: 98
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET,POST,PUT,DELETE,HEAD,OPTIONS,PATCH
Access-Control-Allow-Headers:
X-Requested-With,X-Sequence,X-Ca-Key,X-Ca-Secret,X-Ca-Version,X-Ca-Timestamp,X-Ca-Nonce,X-Ca-API-Key,X-Ca-Stage,X-Ca-Client-DeviceId,X-Ca-Client-AppId,X-Ca-Signature,X-Ca-Signature-Headers,X-Ca-Signature-Method,X-Forwarded-For,X-Ca-Date,X-Ca-Request-Mode,Authorization,Content-Type,Accept,Accept-Ranges,Cache-Control,Range,Content-MD5
Access-Control-Max-Age: 172800
X-Ca-Request-Id: 8E841DE3-7087-4722-9BF1-434C49417E2B
Cache-Control: private
Set-Cookie: ASP.NET_SessionId=tu24y5555sztew4512cnyi45; path=/; HttpOnly
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
{"ReturnStatus":"Success","Message":"ok","RemainPoint":418683,"TaskID":32742224,"SuccessCounts":1}
我们只想要获取到下面的json数据 也就是Body体的时候 怎么办呢
看下关键代码
list($header, $body) = explode("\r\n\r\n", curl_exec($curl), 2);
$body就保存了body部分数据 也就是我们程序需要的json数据了。