$endpoint = rtrim($site->url,"/").'/'.env('WP_ENDPOINT');
try {
$request = Http::post($endpoint);
dd($request);
} catch (GuzzleHttpExceptionConnectException $e) {
$response = json_encode((string)$e->getResponse()->getBody());
}
I am trying to get response from a remote URL using guzzle http client but i get error ‘cURL error 6: Could not resolve host:’ on line 4.
$request = Http::post($endpoint);
I used try catch to handle the error but nothing happened so far.
Any help would be highly appreciated.
2
Answers
actually i didn’t work anytime with laravel guzzle but i read something about guzzle’s requests and you should always catch these two types of common timeouts, connection timeouts and request timeouts can you try like this your post request:
if you find any issue on this code, please notify me!
Do not use
env()
outside the config file.Laravel’s Http client does not throw exceptions unlike Guzzle. Be sure to read the official documentation.
https://laravel.com/docs/11.x/http-client#error-handling