Guzzle client 获取错误码
如何获取Guzzle client的错误码,比如403,看下面的示例
try {
$url = 'https://www.youtube.com/channel/'.'UCwprv8E-H9d_djdg6T26nkw2';
$client = new Client();
$res = $client->request('GET', $url, [
'headers' => [
],
'timeout' => 10, //超时时间(秒)
]);
$statusCode = $res->getStatusCode(); // 获得接口反馈状态码
//$body = $res->getBody();
dd($statusCode);
} catch (RequestException $e) {
if ($e->hasResponse()) {
$response = $e->getResponse();
//will get 404 code
dd($response->getStatusCode());
}
}