php-curl重定向后未发送Authorization标头

时间:2019-01-04 19:34:46

标签: php curl php-curl nest-thermostat

我正在使用PHP 7.2和cURL 7.53.1。我正在尝试使用Google的NEST REST API。

我尝试这样的CURL请求:

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://developer-api.nest.com",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_FOLLOWLOCATION=>true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "GET",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "Authorization: Bearer ".$authkey,
  ),
  CURLINFO_HEADER_OUT=>true
));

$response = curl_exec($curl);
var_dump($response);
var_dump(curl_getinfo($curl, CURLINFO_HEADER_OUT));

我看到了:

string(181) "{"error":"unauthorized","type":"https://developer.nest.com/documentation/cloud/error-messages#auth-error","message":"unauthorized","instance":"63d53235-5548-4d4f-b791-360c53baef4a"}"
string(165) "GET / HTTP/1.1
Host: firebase-apiserver14-tah01-iad01.dapi.production.nest.com:9553
Accept: */*
Accept-Encoding: deflate, gzip
Content-Type: application/json

"

似乎对developer-api.nest.com的请求已重定向到firebase-apiserver14-tah01-i​​ad01.dapi.production.nest.com:9553。好的...但是在随后的请求中,cURL没有发送Authorization标头。奇怪的是,它正在发送Content-type标头...

该请求失败,因为它是未经授权的。

任何帮助表示赞赏。干杯

0 个答案:

没有答案