2017-05-29 59 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 
)); 
相關問題