Method
CurlResponse::getStatusCode
Return the HTTP status code, waiting for the headers to arrive.
Description#
public CurlResponse::getStatusCode(): intA 404 or 500 is returned as a number and throws nothing.
Return values#
int
Errors / Exceptions#
| Exception | When |
|---|---|
NetworkException | When no response headers arrived because of a network failure |
RequestException | When the request is invalid |
ClientException | For any other failure, such as too many redirects |
Examples#
try {
$status = $client->get('https://example.com/')->getStatusCode();
} catch (\Psr\Http\Client\NetworkExceptionInterface $e) {
// connection refused, DNS failure, timeout: $e->getCode() is cURL's error number
}See also#
CurlResponse::getReasonPhraseGets the response reason phrase associated with the status code.