使用Guzzle的Request对象发送参数

时间:2018-12-20 11:28:26

标签: php curl guzzle

我希望查询参数可以通过以下方式发送,但不是。

$response=$myObj->myMethod1(new Request('GET', _VER_.'/endpoint', ['query'=>['hello'=>123]]));

public function myMethod1(\GuzzleHttp\Psr7\Request $request):\GuzzleHttp\Psr7\Response {
    try {
        $response = $this->httpClient->send($request);
    } catch (ClientException $e) {
        //Deal with exceptions
    }
    return $response;
}

然后我尝试了这个,他们是:

$response=$myObj->myMethod2(new Request('GET', _VER_.'/endpoint'), ['query'=>['hello'=>123]]);

public function myMethod2(\GuzzleHttp\Psr7\Request $request, $data):\GuzzleHttp\Psr7\Response {
    try {
        $response = $this->httpClient->send($request, $data);
    } catch (ClientException $e) {
        //Deal with exceptions
    }
    return $response;
}

是否无法在Request对象中添加任何参数?

0 个答案:

没有答案