簡體   English   中英

將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的實例\\給出的響應

嘗試過沒有運氣的修改。

$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的變化,它沒有按預期工作。

你不需要手動調用->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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM