2016-03-14 389 views
0

你好我正在测试端点,当我运行php testing.php时,我得到这个错误。任何帮助将不胜感激。curl(7):无法连接到本地端口8000:连接被拒绝

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 ...

我试过127.0.0.1以及和它没有工作

这里是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"; 
+1

而你认为我们可以帮助连接拒绝错误?这是一个服务器问题,与编程无关。服务器显然拒绝连接,你需要改变它。 –

回答

1

,如果你使用的是Linux,确保服务器运行使用

/etc/init.d/httpd status 
相关问题