【发布时间】:2016-07-12 08:29:50
【问题描述】:
我正在使用http://phphttpclient.com 尝试连接到在 localhost:8090 上运行的简单服务。
我的代码是:
$url = "http://127.0.0.1:8090/animal-speak";
$response = \Httpful\Request::get($url)
->send();
echo "{$response->body}"
我得到这个错误:
致命错误:未捕获的 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 行抛出
我也尝试过使用 Guzzle Http 客户端并得到完全相同的错误,这让我相信这是一个 php / libcurl 问题?该服务肯定已经启动,我可以在浏览器中看到它,并且可以在命令行上 curl 到它。 谢谢
编辑:如果我不使用本地主机,而是使用远程端点,它可以正常工作。
【问题讨论】:
-
127.0.0.1:80 对我来说效果很好。你没有安装防火墙吗?
-
不,没有防火墙运行。在该端口上运行了其他非 php 的东西,这很好