当服务器返回4xx和5xx状态代码时,我想处理Guzzle的错误.我提出这样的请求:
$client = $this->getGuzzleClient();
$request = $client->post($url, $headers, $value);
try {
$response = $request->send();
return $response->getBody();
} catch (\Exception $e) {
// How can I get the response body?
}
Run Code Online (Sandbox Code Playgroud)
$e->getMessage返回代码信息,但不返回HTTP响应的主体.我如何获得响应机构?