[英]Json response on php curl request
我已經發送了一個 curl 請求,我正在以這種方式輸出響應。
$output = curl_exec($ch);
$json = json_decode($output, true);
echo $output;
echo $json;
這是輸出。
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" : "" }
我正在嘗試解碼 json 部分,但 $json 只是 null。 我希望能夠讀取 $json["autoStartToken"]。 我將如何實現這一目標?
正如catcon 提到的:
現在您的 curl 請求也返回標頭,因此您不能直接將 json_decode 與響應一起使用,請嘗試放置
curl_setopt($ch, CURLOPT_HEADER, 0);
在curl_exec($ch)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.