简体   繁体   中英

Json response on php curl request

I have sent a curl request, and I'm outputing the response this way.

$output = curl_exec($ch);
$json = json_decode($output, true);
echo $output;
echo $json;

This is the output.

HTTP/1.1 201 Created Server: nginx/1.15.8 Date: Wed, 02 Sep 2020 23:53:01 GMT Content-Type: application/json Transfer-Encoding: chunked Connection: keep-alive X-Content-Type-Options: nosniff X-XSS-Protection: 1; mode=block Cache-Control: no-cache, no-store, max-age=0, must-revalidate Pragma: no-cache Expires: 0 X-Frame-Options: DENY Strict-Transport-Security: max-age=31536000; includeSubdomains { "orderRef" : "4352fa96-05cc-400e-854c-808e5da7dfd7", "autoStartToken" : "84ead0b7-1ee8-40ed-be82-1168e7cbb16b", "message" : "" }

I'm trying to decode the json part, but $json is just null. I'd like to be able to read $json["autoStartToken"]. How would I achieve this?

As catcon mentions :

Right now your curl request also return the header so you can't directly use json_decode with the respond, try putting curl_setopt($ch, CURLOPT_HEADER, 0); before the curl_exec($ch)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM