标题不是用PHP发送的

时间:2014-11-08 03:58:50

标签: php curl

我有以下代码:

$service_url = 'https://api.familysearch.org/reservation/v1/person/L6GD-YYV';

$curl = curl_init($service_url);
$headr = array();
$headr[] = 'Content-length: 0';
$headr[] = 'Content-type: application/json';
$headr[] = 'Authorization: OAuth '.$_SESSION['fs-session'];

curl_setopt($curl, CURLOPT_HTTPHEADER,$headr);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
//curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);

$curl_res = curl_exec($curl);
$response = json_decode($curl_res);
curl_close($curl);

var_dump($curl_res);
var_dump($response);

当我尝试检索资源时,即使我提供访问令牌,它也会给我401 Unauthorized。然后,我查看了正在发送的标头,发现我通过此代码设置的标头(访问标记标头)都没有被发送。我的代码是否有问题阻止了标题的发送?

1 个答案:

答案 0 :(得分:0)

您需要指定Accept标头和授权类型:

Accept: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN_HERE