【问题标题】:cURL Error : Cannot connect: SSL is disabled. Error number 35cURL 错误:无法连接:SSL 已禁用。错误号 35
【发布时间】:2016-05-07 03:10:10
【问题描述】:

我正在使用 Centos 7 托管在 Digital Ocean 盒子上的一个应用程序中的 paypal ipn 脚本。

当我尝试连接到 paypal 沙盒 api 时,我收到错误“无法连接:SSL 已禁用。”

我尝试了几件事,例如在我的 php.ini 文件中添加 curl.cainfo 的路径,如下所示
curl.cainfo = /etc/pki/tls/certs/ca-bundle.trust.crt

这就是我的 cURL 脚本的样子

// STEP 2: Post IPN data back to paypal to validate

$ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr'); // change to [...]sandbox.paypal[...] when using sandbox to test
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'ecdhe_rsa_aes_128_gcm_sha_256'); 
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

我在 Linux 服务器设置方面没有太多经验,所以我边走边学。 非常感谢任何帮助或指导

更新:当我在命令行中运行这个命令时 curl --version https://sandbox.paypal.com/cgi-bin/webscr

我收到此错误 curl: (1) Protocol "https" not supported or disabled in libcurl

还有命令curl --version 显示curl 7.42.1 (x86_64-unknown-linux-gnu) libcurl/7.46.0

所以我猜新问题是如何在 libcurl 中启用 https?

【问题讨论】:

    标签: php ssl curl paypal


    【解决方案1】:

    您设置了错误的 SSL 版本:

    curl_setopt($ch, CURLOPT_SSLVERSION, 4);

    Paypal sandbox only supports TLS 1.2(即 CURLOPT_SSLVERSION == 6)。如果您使用 PHP 5.5.19+ 和 OpenSSL 1.0.1+,将自动使用正确的 SSL 版本,或者您可以通过以下方式自行强制使用(仍然需要 OpenSSL 1.0.1+):

    curl_setopt($ch, CURLOPT_SSLVERSION, 6);

    【讨论】:

      【解决方案2】:

      我只希望看到Protocol "https" not supported or disabled in libcurl,如果它正在运行从 rpm 安装的 libcurl不是 - 或者如果配置机器的人出于正当理由故意破坏它,或者非常无能;用于 libcurl 的 Centos 7 rpm 需要 openSSL。

      了解此处发生的情况和补救措施将需要对目标主机具有 root 访问权限才能安装软件。您没有说您在目标系统上拥有什么访问权限,并且您可能正在向 Digital Ocean 支付支持费用。除非你自己弄坏了,否则你应该要求 Digital Ocean 修复它。

      【讨论】:

      • libcurl 来自 city-fan.org (7.47.0-1.0.ch.rhel7),因为我在我的 repo 中找不到我想要的 cURL 版本。我对 Linux 服务器没有经验,所以我边走边学。事实上,我得到了数字海洋 vps 来了解 Linux 的工作原理
      • 你在你的问题中说这是一个 CentOS 安装 - 不是一个 Centos 安装,带有来自一些随机来源的附加软件包。 Centos rpm 出了什么问题?
      • Centos rpm 7.29 以上版本没有 cURL
      • 这并没有回答这个问题 - 但鉴于你的答案,让我改写一下:7.47.07 做了什么,而 7.29 没有,并且对你想要实现的目标至关重要?
      【解决方案3】:

      在一位拥有丰富 Linux 经验的朋友的帮助下,我能够解决这个问题。显然这是我的 Digital Ocean 盒子上安装的 cURL 版本的问题。

      所以解决方案是删除我安装的 cURL 版本,但由于我自己构建了二进制文件,所以安装不正确。

      我使用这些命令安装了有问题的 cURL

      wget -O curl.tar.gz http://curl.haxx.se/download/curl-7.42.0.tar.gz
      tar -xvzf curl.tar.gz
      cd curl-7.42.0
       ./configure 
      make
      make install
      

      我删除了有类似 https 问题的有问题的 cURL

      which curl
      

      (告诉我可执行文件的位置,它位于usr/local/bin/curl

      然后我做了

      sudo rm -f /usr/local/bin/curl
      

      (删除 cURL 给出的问题)

      然后我使用了命令

      sudo yum install curl php5-curl
      

      这为我正确安装了 cURL。我跑了

       curl --version
      

      确认 cURL 版本现在支持 https 并且确实支持。

      我退出了我的Droplet并重新登录。然后尝试了

      curl --version "https://sandbox.paypal.com/cgi-bin/webscr" 
      

      命令,一切正常。我能够连接到 Paypal。

      感谢大家的帮助和cmets。

      【讨论】:

        【解决方案4】:

        我认为您需要启用 fopen socket。您可以询问托管服务提供商

        【讨论】:

        • 我该怎么做?我的网站位于 Digital Ocean 的虚拟专用服务器上。
        • fopen 套接字已启用
        • 这篇文章与提出的问题无关。
        猜你喜欢
        • 2016-08-15
        • 2016-09-16
        • 2019-02-13
        • 2018-06-16
        • 2014-03-20
        • 1970-01-01
        • 2011-03-15
        • 2016-04-28
        • 1970-01-01
        相关资源
        最近更新 更多