【问题标题】:Guzzle fails to authenticate with shopware5Guzzle 无法通过 shopware5 进行身份验证
【发布时间】:2021-02-23 17:40:40
【问题描述】:

我正在尝试将以下查询 shopware5 API 的工作 HTTP_Request2 代码移植到 Guzzle 7

$request = new \HTTP_Request2();
$request->setBody('{"limit": 500000}');
$request->setUrl($URL.'/customers');

$request->setMethod(\HTTP_Request2::METHOD_GET);
$request->setHeader('Accept-Encoding','gzip, deflate, br');
$request->setAuth($username, $apiKey, \HTTP_Request2::AUTH_DIGEST);
$response = $request->send();

我尝试了以下方法,但失败并显示消息“无效或缺少身份验证”

$RESTClient = new Client();
        $request = new Guzzle_request(
            'GET',
            $URL  .'/customers',
            [
                'body' => '{"limit": 500000}',
                'decode_content' => 'gzip, deflate, br',
                'auth' => [$username, $apiKey, 'digest']
            ]);
 $response = $RESTClient->send($request);

【问题讨论】:

  • 您使用的是什么版本的 guzzle?

标签: php guzzle shopware shopware5


【解决方案1】:

您需要更改您的代码

use GuzzleHttp\Psr7\Request;

$client = new GuzzleHttp\Client();
$headers = ['Accept-Encoding' => 'gzip, deflate, br'];
$body = '{"limit": 500000}';
$request = new Request('GET', $URL . '/customers', $headers, $body);
$response = $client->send($request, [
                                  'verify' => false,
                                  'auth' => [$username, $apiKey, 'digest']  
                              ]);

由于 Digest 具有 md5,因此验证为 false 并不会使其不安全,但我在任何地方都没有找到为什么写的原因,但看到摘要仅适用于验证为 false。

你也可以继续使用decode_content 没问题,虽然默认情况下它是真的,所以如果我通过标题,那么我想没有问题。

【讨论】:

    猜你喜欢
    • 2012-04-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 2015-09-15
    • 2017-08-31
    • 2018-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多