2017-04-04 66 views
0
`curl -H "Authorization: Token token=YOUR_TOKEN" https://api.upcall.com 
/api/v1/calls` 

如何在PHP中使用是指如何在PHP請求在URL發送令牌

$service_url = "https://api.upcall.com/api/v1/calls"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $service_url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: 12345' // you can replace this with your $auth variable 
)); 
+1

什麼是問題?哦..現在我明白了...... –

+0

[如何通過curl調用使用HTTP請求發送頭文件?](http://stackoverflow.com/questions/356705/how-to-send-a-頭部使用一個HTTP請求通過一個捲曲調用) –

+0

獲得數據捲曲-H「授權:令牌令牌= YOUR_TOKEN」https://api.upcall.com /api/v1 /調用如何在PHP中獲取數據? – SirajuddinLuck

回答

0

你的API調用應該像這樣:

$service_url = "https://api.upcall.com/api/v1/calls"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $service_url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Token token=YOUR_TOKEN' 
    )); 
$result = curl_exec ($ch); 
curl_close ($ch); 

以上是PHP的轉換curl命令:

curl -H "Authorization: Token token=YOUR_TOKEN" https://api.upcall.com/api/v1/calls 
+0

https://upcall.github.io/api-docs/?shell#calls – SirajuddinLuck

+0

@SirajuddinLuck能解決你的問題嗎? –

+0

返回值false表示無效 – SirajuddinLuck

0
$url = 'https://api.upcall.com/api/v1/calls'; 
    $headers = array (
      'Authorization: token=YOUR_TOKEN' 
    ); 
    $ch = curl_init(); 
    curl_setopt ($ch, CURLOPT_URL, $url); 
    curl_setopt ($ch, CURLOPT_POST, true); 
    curl_setopt ($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt ($ch, CURLOPT_POSTFIELDS, $fields); 
    $result = curl_exec ($ch); 
    curl_close ($ch); 
+0

get方法not post方法 – SirajuddinLuck