【问题标题】:Curl is not working from a https siteCurl 在 https 站点上不起作用
【发布时间】:2015-02-26 09:58:55
【问题描述】:

我在窗口服务器中托管了一个 Web 服务 (WSL)(仅限 HTTP)。

我的网站托管在使用 ssl (https) 的 linux 服务器中

如果我使用 curl 从带有 HTTPS 的 linux 服务器域向我的 Web 服务 (WSL) 获取/发布数据,则它不起作用。

它抛出错误“无法连接到主机”。

但是,如果我尝试从本地机器向我的 Web 服务 POST / GET 数据,curl 正在工作。

这是我的代码,任何人都可以提出问题所在:

$ch = curl_init('服务域');

        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
        curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data );  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
            'Content-Type: application/json',                                                                                
            'Content-Length: ' . strlen($json_data)   
        ));                                                                          
        $result = curl_exec($ch);
        echo curl_error($ch);
        curl_close($ch); 

以前有没有人遇到过同样的问题。

【问题讨论】:

    标签: php curl https


    【解决方案1】:

    “无法连接到主机”

    这意味着该站点无法通过 https 访问。 由于 https 在不同的端口上使用然后 http 它可能意味着 https 可能没有在服务器上设置(如果它正在侦听 0.0.0.0:443、127.0.0.1:443,请在 linux 系统上检查 netstat -nlt是不够的)或者在阻止连接之间有防火墙。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-26
      • 2016-07-20
      • 1970-01-01
      • 2012-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多