下面是一个有效的 C# get 请求
public HttpResponseMessage ExecuteEndPoint(string endpoint,string accessTocken) {
HttpResponseMessage responseMessage = new HttpResponseMessage();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessTocken);
responseMessage = client.GetAsync(endpoint).Result;
}
return responseMessage;
}
我想使用curl在php中执行相同的请求,下面是我尝试过的
$request_headers=array();
$request_headers[]='Bearer: '.$access_token;
//$request_headers[]='Content-Length:150';
$handle1=curl_init();
$api_url='here my api get url';
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);
看起来 api 没有收到 access_token。
任何帮助表示赞赏。
谢谢
您还需要指定“授权”...
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Authorization: Bearer ".$access_token
));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)