PHP Curl +连接被拒绝 [英] PHP Curl+connection refused

查看:780
本文介绍了PHP Curl +连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的PHP Curl中收到此错误

I am getting this error in my PHP Curl

* Hostname in DNS cache was stale, zapped
*   Trying xxx.xx.x.xx...
* connect to xxx.xx.x.xx port 4005 failed: Connection refused
* Failed to connect to sample.website.net.au port 4005: Connection refused
* Closing connection 0

我有此代码:

$ch = curl_init();
    $headers = array(
        'Content-type: text/xml',
        'charset: utf-8',
        'SOAPAction: urn:ServiceQualification#AddresSsearch',
    );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    $verbose = fopen('php://temp', 'w+');
    curl_setopt($ch, CURLOPT_STDERR, $verbose);

    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false); // This should always be set to 'TRUE' when in production to ensure the SSL is enabled.
    $response = curl_exec ($ch);    

    if ($result === FALSE) {
        printf("cUrl error (#%d): %s<br>\n", curl_errno($ch),
               htmlspecialchars(curl_error($ch)));
    }

    rewind($verbose);
    $verboseLog = stream_get_contents($verbose);

    echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";

    curl_close ($ch);

    return $response;

我不知道为什么会出现此错误。我在我的本地主机中尝试了这个,它运行良好,但是当我将其上传到服务器时,出现了上述的php curl错误。

I don't know why I am having this error. I tried this one in my localhost, and it works perfectly, but when I uploaded it in my server, I am getting the said php curl error.

似乎是什么这里的问题?我需要联系我要连接的网址吗?

What seems to be the problem here? Do I need to contact the url that I am trying to connect?

我现在正在head头,将非常感谢您的帮助。

I am banging my head now, your help will be greatly appreciated.

谢谢!

推荐答案

连接被拒绝:

检查是否可以将出口连接到端口4005。可能是防火墙阻止了您。

Check if you may connect outgoing to port 4005. Possibly it's your firewall that blocks you.

检查是否可以将出口连接到端口4005。可能是远程防火墙阻止了您。

Check if you may connect outgoing to port 4005. Possibly it's the remote firewall that blocks you.

检查是否可以通过终端ping远程主机:

Check if you can ping the remote host via your terminal:

ping 1.2.3.4 // this is the ip, you can also use the hostname.

尝试通过终端将远程主机与特定端口连接:

Try connecting the remote host with specific port via your terminal:

telnet 1.2.3.4 4005

此比通过php代码进行调试更容易。

This is more easy than debugging via php code.

这篇关于PHP Curl +连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆