使用CURL发送头并接收Json数据-PHP
我收到一个错误,不确定这是否是一个标题错误?当我使用具有相同标题和URL的Postman时,提要可以100%工作使用CURL发送头并接收Json数据-PHP,php,json,curl,Php,Json,Curl,我收到一个错误,不确定这是否是一个标题错误?当我使用具有相同标题和URL的Postman时,提要可以100%工作 {"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:vd
{"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;
我将标题从
$headers = array(
'Accept:vdn.v1',
'Content-Type:application/json'
);
到
已对所有问题进行排序错误表明您的Accept标头存在问题。检查字符串
'Accept:vdn.v1'
@jorgonor中是否有任何错误,我在postman和我的php代码中再次检查了Accept:vdn.v1是否正确如果它在postman中工作,请单击右上角的“代码”链接,在“生成代码片段”弹出窗口中选择“php cURL”。生成的代码可以粘贴到您的脚本中,并且应该生成相同的http请求。@AlexBlex感谢您指导我完成PHP curl代码段,我使用了完全相同的代码,仍然是相同的错误(:很高兴它有帮助,但它几乎不能作为答案。如果您将代码与Postman生成的代码片段进行比较,您可以发现差异,将其作为答案发布,然后接受它。
$headers = array(
'Accept:vdn.v1'
);