将 guzzle 代码从 guzzle 5 更改为 guzzle 6 时遇到错误
Facing error in changing a guzzle code from guzzle 5 to guzzle 6
GuzzleHttp\Client::send() 必须实现接口 Psr\Http\Message\RequestInterface,给定 GuzzleHttp\Psr7\Response 的实例
试过修改,没有成功。
$request = $client->request('GET', $url, [
'timeout' => 15,
'exceptions' => false,
'keepalive' => true
]);
$response = $client->send($request);
$body = $response->getBody();
$content = $body ? $body->getContents() : '';
$code = $response->getStatusCode();
我希望发送请求能够成功发送。然而,由于 guzzle 6 的变化,它没有按预期工作。
您不需要手动调用 ->send()
,实际请求已经在 ->request()
中完成。这就是您在错误中看到 GuzzleHttp\Psr7\Response
的原因。
所以只需删除发送线即可。
$response = $client->request('GET', $url, [
'timeout' => 15,
'exceptions' => false,
'keepalive' => true
]);
$body = $response->getBody();
$content = $body ? $body->getContents() : '';
$code = $response->getStatusCode();
GuzzleHttp\Client::send() 必须实现接口 Psr\Http\Message\RequestInterface,给定 GuzzleHttp\Psr7\Response 的实例
试过修改,没有成功。
$request = $client->request('GET', $url, [
'timeout' => 15,
'exceptions' => false,
'keepalive' => true
]);
$response = $client->send($request);
$body = $response->getBody();
$content = $body ? $body->getContents() : '';
$code = $response->getStatusCode();
我希望发送请求能够成功发送。然而,由于 guzzle 6 的变化,它没有按预期工作。
您不需要手动调用 ->send()
,实际请求已经在 ->request()
中完成。这就是您在错误中看到 GuzzleHttp\Psr7\Response
的原因。
所以只需删除发送线即可。
$response = $client->request('GET', $url, [
'timeout' => 15,
'exceptions' => false,
'keepalive' => true
]);
$body = $response->getBody();
$content = $body ? $body->getContents() : '';
$code = $response->getStatusCode();