经过测试用一下方式设置 header 参数,可以成功获取数据
- $accessToken = "6666666666669999999999";
- $headers[] = "Accept:application/json";
- $headers[] = "Authorization: Bearer ". $accessToken;
curl 参数设置如下:
- if( !empty($headers) ){
- curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers );
- }
curl请求方法
- function curl_post($url, $data ,$aHeader=[]) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- $tmpInfo = curl_exec($ch);
- if (curl_errno($ch)) {
- return false;
- }else{
- return $tmpInfo;
- }
- }
文章点评