简体   繁体   English

无法从Httpful PHP Rest客户端连接到localhost

[英]Can't connect to localhost from Httpful php rest client

I am using http://phphttpclient.com to try to connect to a simple service running on localhost:8090. 我正在使用http://phphttpclient.com尝试连接到在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 致命错误:Httpful \\ Exception \\ ConnectionErrorException未捕获:无法连接到“ http://127.0.0.1:8090/animal-speak”:7无法连接到127.0.0.1端口8090:/ var / www / vendor中的连接被拒绝/nategood/httpful/src/Httpful/Request.php:1028堆栈跟踪:#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}放在/var/www/vendor/nategood/httpful/src/Httpful/Request.php中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? 我也尝试过使用Guzzle Http客户端,并且得到完全相同的错误,这使我相信这是php / libcurl问题? 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. 我在Docker容器中运行服务,但尚未设置网络。

My apologies for wasting time! 很抱歉浪费时间!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM