【问题标题】:Guzzle 6 Async request return Argument 1 passed must be of the type array, string given,Guzzle 6 异步请求返回传递的参数 1 必须是数组类型,给定字符串,
【发布时间】:2017-01-20 01:05:41
【问题描述】:

我正在尝试进行异步 POST 调用,但 guzzle 调用返回以下错误:

" Request.php 第 220 行中的错误异常: 传递给 Symfony\Component\HttpFoundation\Request::__construct() 的参数 1 必须是数组类型,给定字符串,在第 87 行的 C:\Program Files ...\app\Http\Controllers\ConfirmAccountController.php 中调用,并且定义 "

在 ConfirmAccountController 中:

$client = new Client(['base_uri' => 'correct_api_address']);

$request = new Request('POST', 'testpromoboiler/updateUser',  [
        'query' => ['token' => $user->sdg_token ,
                    'address' => $user->address ,
                  ]
    ]);

$promise = $client->sendAsync($request)->then(function ($response) {
    echo 'I completed! ' . $response->getBody();
});

$promise->wait();

为什么会出现此错误?

我已经完成了另外两个同步调用,一切都很顺利。

谢谢

【问题讨论】:

  • Symfony\Component\HttpFoundation\Request 中的前 2 个参数是数组。第一个是 GET 参数,第二个是 POST 参数。不确定 Client 对象在您的代码中指的是什么,但您可能应该在其中添加方法和 URL,而不是在请求对象中。

标签: laravel guzzle guzzle6


【解决方案1】:

该代码实例化 Laravel 框架 Request 类。

改用 guzzles 请求方法:

$request = $client->request('POST', 'testpromoboiler/updateUser',  [
        'query' => ['token' => $user->sdg_token ,
                    'address' => $user->address ,
                  ]
    ]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-18
    • 2018-03-22
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    • 2020-01-06
    • 2022-08-21
    • 1970-01-01
    相关资源
    最近更新 更多