狂饮摘要验证不起作用 [英] Guzzle digest auth not working
问题描述
我正在尝试制作一个将摘要用作身份验证的API,当我使用该命令通过curl命令行访问API时,就可以了
I'm trying to make an API that use digest as authentication, When I access API via curl command line using this command, it's work
curl --digest --user website:website http://localhost/api/test/users
但是在使用 Guzzle 6 php库并使用此代码运行api客户端时
but when running api client using Guzzle 6 php library using this code
$handler = new GuzzleHttp\Handler\CurlHandler();
$stack = GuzzleHttp\HandlerStack::create($handler); // Wrap w/ middleware
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost', 'handler' => $stack]);
try {
$request = new GuzzleHttp\Psr7\Request('GET', $req_uri, [
'auth' => ['website', 'website', 'digest']
]);
$response = $client->send($request, ['timeout' => 2]);
} catch (Exception $e) {
echo $e->getMessage();
die();
}
return $response;
它不起作用,它说
401未经授权的响应:{状态":false,错误":未经授权"}
401 Unauthorized` response: {"status":false,"error":"Unauthorized"}
该如何解决?以及如何以正确的方式实现自定义处理程序guzzle php?
how to fix this? and how to implement custom handler guzzle php in the right way ?
推荐答案
我遇到了同样的问题,并且发现根本没有安装php-curl扩展名.安装后,摘要身份验证有效.要安装扩展程序类型:
I had the same issue and I noticed php-curl extension wasn't installed at all. After installing it digest auth worked. To install the extension type:
sudo apt-get install php-curl
这篇关于狂饮摘要验证不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!