Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php对Vebra提要进行身份验证?_Php_Curl - Fatal编程技术网

如何使用php对Vebra提要进行身份验证?

如何使用php对Vebra提要进行身份验证?,php,curl,Php,Curl,有人使用过Vebra API吗?在他们的文档中,他们有一个用于身份验证的C#示例,但我将使用php。它们使用编码为base 64的用户名:密码对指定HTTP基本身份验证 初始调用需要username:password对,结果是一个令牌。后续调用需要在给定的时间范围内(一小时)使用此令牌 我在使用curl进行身份验证时遇到问题,更不用说确定我需要的响应头中的令牌了 我是否使用了正确的选项 这是我写的一个基本的卷曲练习。。。 $ch = curl_init(); curl_setopt($ch, C

有人使用过Vebra API吗?在他们的文档中,他们有一个用于身份验证的C#示例,但我将使用php。它们使用编码为base 64的用户名:密码对指定HTTP基本身份验证

初始调用需要username:password对,结果是一个令牌。后续调用需要在给定的时间范围内(一小时)使用此令牌

我在使用curl进行身份验证时遇到问题,更不用说确定我需要的响应头中的令牌了

我是否使用了正确的选项

这是我写的一个基本的卷曲练习。。。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);

$result = curl_exec($ch);

// Handle the result - fail or success
if (!curl_errno($ch)) {

// get the response headers
//$info = curl_getinfo($ch);

var_dump ($result);
var_dump (curl_getinfo($ch));

// extract the token from the response header
//....
}
curl_close($ch);
?>

今天早上我一直在努力解决这个问题,但我想我已经解决了。因此,我将在这里总结我的代码:

// get token
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$userpass = "$username:$password";
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($userpass) )); // I found this to be the only way of consistently authorising between user-password combo and using a token

$response = curl_exec($ch);

// little bit of nasty parsing code    
list($headers, $body) = explode("\r\n\r\n", $response);
$headers = nl2br($headers);
$headers = explode('<br />', $headers);

foreach($headers as $header) {
    $components = explode(': ', trim($header));
    $headers[$components[0]] = $components[1];
}

$token = $headers['Token'];

我一直在使用
curl\u getinfo()
检查401状态代码并刷新令牌。

今天早上我一直在努力解决这个问题,但我想我已经破解了它。因此,我将在这里总结我的代码:

// get token
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); 
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_URL, $url);
$userpass = "$username:$password";
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic '.base64_encode($userpass) )); // I found this to be the only way of consistently authorising between user-password combo and using a token

$response = curl_exec($ch);

// little bit of nasty parsing code    
list($headers, $body) = explode("\r\n\r\n", $response);
$headers = nl2br($headers);
$headers = explode('<br />', $headers);

foreach($headers as $header) {
    $components = explode(': ', trim($header));
    $headers[$components[0]] = $components[1];
}

$token = $headers['Token'];

我一直在使用
curl\u getinfo()
检查401状态代码并刷新令牌。

VERBA api的文档在哪里?我似乎找不到它…?我也可以用这个文档…VERBA api的文档在哪里?我似乎找不到它…?我也可以用这个文档。。。