【发布时间】:2020-08-06 17:22:33
【问题描述】:
这是我的 curl PHP 中出现的错误
HTTP/1.1 401 Unauthorized Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 过期:-1 服务器:Microsoft-IIS/10.0 X-AspNet-Version:4.0.30319 WWW-Authenticate:Bearer WWW-Authenticate:Bearer X-Powered-By:ASP.NET 日期:星期四,4 月 23 日2020 年 10:57:54 GMT Content-Length: 61 {"Message":"Authorization has been denied for this request."}";
API 没有收到访问令牌,我认为它缺乏授权。请帮助我使用下面的授权代码正确添加我的代码,我有点困惑在哪里添加它。
下面是授权码
curl_setopt($handle1, CURLOPT_HTTPHEADER, array("Authorization: Bearer ".$access_token));
//我写的代码
<?php
$access_token = $_SESSION['token'];
$request_headers = array();
$request_headers[] = 'Bearer: ' . $access_token;
//$request_headers[]='Content-Length:150';
$handle1 = curl_init();
$api_url = 'API';
curl_setopt_array(
$handle1,
array(
CURLOPT_URL => $api_url,
CURLOPT_POST => false,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $request_headers,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_TIMEOUT => -1,
)
);
$data = curl_exec($handle1);
echo serialize($data);
?>
【问题讨论】:
-
非常感谢它现在正在工作..非常感谢您的帮助
-
然后我将评论切换为答案
标签: php curl authorization