2017-05-29 60 views
1
下面

是工作的C#GET请求如何在curl中使用持票人令牌获取请求标头?

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 。 任何帮助表示赞赏。 感谢

回答

1

您还需要指定 “授权” ......

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Authorization: Bearer ".$access_token 
)); 
相关问题