php curl (7): 无法连接到本地主机端口 8000: 连接被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35978180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
curl (7): Failed to connect to localhost port 8000: Connection refused
提问by Ris
Hello I am testing the endpoint and when I run php testing.php I get this error. Any help would be appreciated it.
您好,我正在测试端点,当我运行 php testing.php 时出现此错误。任何帮助将不胜感激。
Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 7: Failed to connect to localhost port 8000: Connection refused [url] http://localhost:8000/api/programmers' guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:359 ...
Fatal error: Uncaught exception 'Guzzle\Http\Exception\CurlException' with message '[curl] 7: Failed to connect to localhost port 8000: Connection refused [url] http://localhost:8000/api/programmers' guzzle\guzzle\src\Guzzle\Http\Curl\CurlMulti.php:359 ...
I've tried 127.0.0.1 as well and it didnt work
我也试过 127.0.0.1 但没有用
here is testing.php
这是testing.php
<?php
require __DIR__.'/vendor/autoload.php';
use Guzzle\Http\Client;
// create our http client (Guzzle)
$client = new Client('http://localhost:8000', array(
'request.options' => array(
'exceptions' => false,
)
));
$nickname = 'ObjectOrienter'.rand(0, 999);
$data = array(
'nickname' => $nickname,
'avatarNumber' => 5,
'tagLine' => 'a test dev!'
);
$request = $client->post('/api/programmers', null, json_encode($data));
$response = $request->send();
echo $response;
echo "\n\n";
采纳答案by Ahmed H. Saab
if you are using linux, make sure the server is running using
如果您使用的是 linux,请确保服务器正在使用
/etc/init.d/httpd status
回答by shoeab
I was facing the same, when http://localhost:8000or http://127.0.0.1:8000neither worked. I solved it using my network IP like
我面临同样的情况,当http://localhost:8000或http://127.0.0.1:8000都不起作用时。我使用我的网络 IP 解决了它
192.168.0.3:8000
回答by Rahul Rahatal
Check if your localhost:8000 server is running.
If it is not then start it using following command from terminal.
Go to root folder of your project & type,
检查您的 localhost:8000 服务器是否正在运行。
如果不是,则从终端使用以下命令启动它。
转到项目的根文件夹并键入,
php -S localhost:8000 -t .\public
回答by Matt Doran
If you are running localhost like so:
如果您像这样运行本地主机:
php -S localhost:8000
php -S 本地主机:8000
and then running curl from a different environment like vagrant then localhost on your vagrant is not the same as localhost on your local machine.
然后从不同的环境(如 vagrant)运行 curl,然后 vagrant 上的 localhost 与本地机器上的 localhost 不同。