我在 PHP 中使用 Curl 来调用API。
根据他们的文档,他们在返回页面的标题中返回“Authentication-Callback”。
当我将 URL 粘贴到浏览器中时,它工作得很好,但 Curl 似乎忽略了它。
这是我的代码
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://api.themoviedb.org/3/authentication/token/new?api_key=[MY_API_KEY]&language=en');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$results = curl_exec($ch);
$headers = curl_getinfo($ch);
这是返回的标题
Array
(
[url] => http://api.themoviedb.org/3/authentication/token/new?api_key=[MY_API_KEY]&language=en&
[content_type] => application/json;charset=utf-8
[http_code] => 200
[header_size] => 470
[request_size] => 137
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.109
[namelookup_time] => 0
[connect_time] => 0.047
[pretransfer_time] => 0.047
[size_upload] => 0
[size_download] => 116
[speed_download] => 1064
[speed_upload] => 0
[download_content_length] => 116
[upload_content_length] => 0
[starttransfer_time] => 0.109
[redirect_time] => 0
[certinfo] => Array
(
)
)
据我所知,一切都是正确的。Curl 返回我完全需要的数据,而不是正确的标题。
任何帮助表示赞赏!