[英]php curl rest api response not in json format
我正在執行卷曲請求
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers = ["Content-Type:application/json","Accept:application/json"];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close ($ch);
return $result;
上面的curl請求應該返回json格式的字符串,但會以javascript對象的形式獲取字符串。
string(68) "{data:{errorCode:AC01,errorMessage:SansID 53563857 is exist.}}"
當我嘗試從post man api做同樣的事情時,返回的是完美的json。
{"data":{"errorCode":"AC01","errorMessage":"SansID 53563857 is exist."}}
請讓我知道我在哪里做錯了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.