通过PHP Curl调用获取数据
我正在尝试进行一个PHP Curl调用。该呼叫在“邮递员”中工作,看起来像:通过PHP Curl调用获取数据,php,api,rest,curl,postman,Php,Api,Rest,Curl,Postman,我正在尝试进行一个PHP Curl调用。该呼叫在“邮递员”中工作,看起来像: URL Endpoint: https://api.sb.example.com/v1/resource/identifier Headers: Content Type: application/json Authorization : Bearer AccessTokenValue HTTP Protocol : GET 这个调用返回一个有效的JSON响应。现在,当我使用PHP做同样的事情时,我无法得到响应
URL Endpoint: https://api.sb.example.com/v1/resource/identifier
Headers:
Content Type: application/json
Authorization : Bearer AccessTokenValue
HTTP Protocol : GET
这个调用返回一个有效的JSON响应。现在,当我使用PHP做同样的事情时,我无法得到响应。以下是我的PHP Curl调用:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sb.example.com/v1/resource/identifier");
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type : application/json',
'Authorization : Bearer AccessTokenValue'
));
$data = curl_exec($ch);
print_r($data);
curl_close($ch);
通过PHP进行的此调用显示错误:
HTTP/1.1 401 Unauthorized
Server: Apache-Coyote/1.1
对代码有什么想法/建议吗?请在curl_exec()之前添加以下所述行
所以我发现,在键值对中的headers数组中有一个空格
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type : application/json', ..)
应该是的
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',