Laravel: GuzzleHttp\Exception\ConnectException: cURL Error 7: Connection failed
P粉388945432
P粉388945432 2023-11-09 18:54:47
0
1
536

I'm trying to publish a 3rd party Api with raw principal using my controller, when I test it from localhost it works fine, but when I publish my project on the server (Cpanel) I get This error:

GuzzleHttpExceptionConnectException: cURL Error 7: Connection failed.

Here is a sample of my code inside the controller:

use IlluminateSupportFacadesHttp; public function testApi(){ $array = [ 'FullName' => 'Full Name', 'PhoneNumber' => '9999999999', 'Date' => '2022-06-26 17:20', 'Note' => '', ]; try { $response = Http::withBody(json_encode($array) , 'application/json') ->post('https://example'); return $response->status(); } catch (Exception $exception){ return $exception; } }

I also tried using GuzzleHttp and the same thing it works on localhost but doesn't work when I publish the project on the server.

use GuzzleHttpClient; public function testApi(){ $array = [ 'FullName' => 'Full Name', 'PhoneNumber' => '9999999999', 'Date' => '2022-06-26 17:20', 'Note' => '', ]; try { $client = new Client(); $response = $client->request('POST', 'https://example', [ 'body' => json_encode($array), 'headers' => [ 'Content-Type' => 'application/json', ] ]); return $response->getStatusCode(); } catch (Exception $exception){ return $exception; } }


P粉388945432
P粉388945432

reply all (1)
P粉939473759

Before disabling the firewall and testing again.

Firewalls may be blocking your request

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!