的file_get_contents:连接被拒绝

问题描述:

我有它运行在我的电脑上正常,但无法在网上下面的代码:的file_get_contents:连接被拒绝

<?PHP 
    header("Content-Type: text/plain"); 

    $username = "username"; 
    $password = "password"; 
    $url = "http://s6.voscast.com:7158/admin.cgi?mode=viewxml"; 

    $context = stream_context_create(array(
     'http' => array (
      'method' => "GET", 
      'header' => "Authorization: Basic ".base64_encode($username.":".$password)."\r\n". 
         "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/11.04 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/535.1" 
     ) 
    )); 

    print file_get_contents($url, false, $context); 
?> 

这完全本地工作;我能够获取HTTP-Basic身份验证背后的URL并将其打印出来。

然而,当我把它上传到我的服务器,它不工作,并吐出了这一点:

<br /> 
<b>Warning</b>: file_get_contents(http://s6.voscast.com:7158/admin.cgi?mode=viewxml) [<a href='function.file-get-contents'>function.file-get-contents</a>]: failed to open stream: Connection refused in <b>/home/livshin/public_html/wp-content/uploads/_radio/songinfo.php</b> on line <b>16</b><br /> 

有没有一种方法,我可以在此得到一个堆栈跟踪或东西,将至少给我更好的信息出了什么问题?

*我已经过测试,确保类似file_get_contents("http://google.com/")这样的东西在服务器上正常工作。

+4

您的服务器可能不允许在端口7158上传出连接。位于端口80上的Google正常工作。你能改变防火墙吗? – Ryan

+1

“堆栈跟踪”最好的办法是使用服务器上的网络监视器,并观察与该服务器的连接会发生什么情况。试一试,你可以将标题设置为一个数组(而不是用“\ r \ n”')作为字符串。根据内部注册的'http://'streamwrapper,这可能会有所不同。但不保证这是有效的。你有SSH访问服务器(shell)吗?也许在命令行中使用'curl -v',你会得到更多的信息,特别是那个部分,就像minitech所评论的那样。 – hakre

+0

@minitech这绝对听起来像这个问题。刚刚要求SSH访问。 –

您的服务器可能不允许在端口7158上传出连接。位于端口80上的Google正常工作。您可能需要更改防火墙。