将guzzle代码从guzzle 5更改为guzzle 6时遇到错误

问题描述 投票:0回答:1

GuzzleHttp \ Client :: send()必须实现接口Psr \ Http \ Message \ RequestInterface,GuzzleHttp \ Psr7的实例\给出的响应

尝试过没有运气的修改。

$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(); 

我希望发送请求成功发送。然而,由于喷嘴6的变化,它没有按预期工作。

php guzzle guzzle6
1个回答
0
投票

您无需手动调用->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();
© www.soinside.com 2019 - 2024. All rights reserved.