在网址中发送令牌

时间:2017-04-04 12:12:04

标签: php api curl

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

如何在php中使用意味着如何在php中请求

$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
));

2 个答案:

答案 0 :(得分: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 );

以上是curl命令的php转换:

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

答案 1 :(得分: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 );
相关问题