PHP - CURL - 连接被拒绝

时间:2017-07-11 17:25:49

标签: php curl cgi

我试图连接到远程服务:

function test(){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://myhost.ddns.net/myfile.cgi');
    curl_setopt($ch, CURLOPT_USERPWD, "user:password");
    curl_setopt($ch, CURLOPT_PORT, 10000);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

    if(curl_exec($ch) === false)
    {
        echo 'Curl error: ' . curl_error($ch).'<br>';
        $info = curl_getinfo($ch);
        print_r($info);
    }
    else
    {
        echo 'Operation completed without any errors';
    }

    // Close handle
    curl_close($ch);
}

但我总是得到这个输出:

    Curl error: Failed to connect to myhost.ddns.net port 10000: Connection refused
    Array
    (
        [url] => http://myhost.ddns.net/myfile.cgi
        [content_type] => 
        [http_code] => 0
        [header_size] => 0
        [request_size] => 0
        [filetime] => -1
        [ssl_verify_result] => 0
        [redirect_count] => 0
        [total_time] => 0.261142
        [namelookup_time] => 0.060601
        [connect_time] => 0
        [pretransfer_time] => 0
        [size_upload] => 0
        [size_download] => 0
        [speed_download] => 0
        [speed_upload] => 0
        [download_content_length] => -1
        [upload_content_length] => -1
        [starttransfer_time] => 0
        [redirect_time] => 0
        [redirect_url] => 
        [primary_ip] => 
        [certinfo] => Array
            (
            )

        [primary_port] => 0
        [local_ip] => 
        [local_port] => 0
    )

如果我尝试在浏览器上访问http://myhost.ddns.net:10000/myfile.cgi,我会收到用户/ pass auth和200code的提示。这只是CURL无法正常工作......

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

最后我的托管阻止了端口10000.我要求解锁它,现在可以正常工作。

谢谢大家。