0
我收到一個錯誤,不知道這是否爲頭錯誤?飼料工程100%,當我使用郵差用相同的標題和URL用CURL發送標題並接收Json數據 - PHP
{"error":{"message":"The content version specified in the request is not supported.","code":101}}
這裏是我想,我的PHP代碼
$url = 'http://x.x.x.x/api/slot/0/io/';
$headers = array(
'Accept:vdn.v1',
'Content-Type:application/json'
);
$ch = curl_init();
// Now set some options (most are optional)
// Set URL to download
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// Set a referer
curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
// User agent
curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");
// Include header in result? (0 = yes, 1 = no)
curl_setopt($ch, CURLOPT_HEADER, 0);
$headers
// Should cURL return or print out the data? (true = return, false = print)
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
// Download the given URL, and return output
$output = curl_exec($ch);
// Close the cURL resource, and free system resources
curl_close($ch);
print_r($output);exit;
錯誤表明您的Accept頭存在問題。檢查字符串「Accept:vdn.v1」中是否有任何拼寫錯誤。 – jorgonor
@jorgonor我再次檢查郵差和我的PHP代碼接受:vdn.v1是正確的 – user580950
如果它在郵差工程中,單擊右上角的'代碼'鏈接,在「生成代碼段」彈出式選擇「PHP曲線」。生成的代碼可以很容易粘貼到腳本中,並生成相同的http請求。 –