Exception
RequestException
The request could not be sent because it is invalid.
Introduction#
Thrown for a URL without a host and for a URL scheme that cURL does not support. The code is cURL's error number.
Class synopsis#
class RequestException extends ClientException implements \Throwable, \Stringable, ClientExceptionInterface, RequestExceptionInterface {
}Examples#
use phasync\HttpClient\HttpClient;
use phasync\HttpClient\RequestException;
use phasync\Psr\Request;
$client = new HttpClient();
foreach (['foo://example.com/', '/no-host'] as $url) {
try {
$client->sendRequest(Request::create('GET', $url));
} catch (RequestException $e) {
// the request was invalid: nothing went over the network
echo $e->getMessage(), "\n";
}
}Output
Protocol "foo" not supported or disabled in libcurl URL rejected: No host part in the URL
try {
$client->sendRequest(\phasync\Psr\Request::create('GET', '/no/host'));
} catch (\Psr\Http\Client\RequestExceptionInterface $e) {
echo $e->getMessage();
}See also#
NetworkExceptionNo response arrived, or the response stopped arriving, because of a network failure.ClientExceptionA request failed for a reason that is neither an invalid request nor a network failure.HttpClient::sendRequestSend a PSR-7 request with the client's default options.