I am using http://phphttpclient.com to try to connect to a simple service running on localhost:8090.
My code is:
$url = "http://127.0.0.1:8090/animal-speak";
$response = \Httpful\Request::get($url)
->send();
echo "{$response->body}"
and I get this error:
Fatal error: Uncaught Httpful\\Exception\\ConnectionErrorException: Unable to connect to " http://127.0.0.1:8090/animal-speak ": 7 Failed to connect to 127.0.0.1 port 8090: Connection refused in /var/www/vendor/nategood/httpful/src/Httpful/Request.php:1028 Stack trace: #0 /var/www/vendor/nategood/httpful/src/Httpful/Request.php(204): Httpful\\Request->buildResponse(false) #1 /var/www/html/index.php(17): Httpful\\Request->send() #2 {main} thrown in /var/www/vendor/nategood/httpful/src/Httpful/Request.php on line 1028
I have also tried using Guzzle Http client as well and get exactly the same error which leads me to believe this is a php / libcurl problem? The service is definitely up, I can see it in the browser and can curl to it on the command line. Thanks
EDIT: if I don't use localhost, and instead use a remote endpoint it works fine.
my bad.
I was running the service in a Docker container and hadn't setup the network.
My apologies for wasting time!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.