【问题标题】:SSL Connection Error even when VERIFYPEER, VERIFYHOST disabled即使禁用 VERIFYPEER、VERIFYHOST 也会出现 SSL 连接错误
【发布时间】:2014-07-26 20:26:46
【问题描述】:

我目前正在构建一个脚本来完成一些 SSL curl 请求,但是我没有成功完成这些请求。我从 curl_error() 收到的只是一个简单的“SSL 连接错误” 字符串......这根本没有帮助。我尝试插入一个有效的自签名证书,完全禁用验证(如下面的代码所示),以及一百万和一个其他配置差异,但我一直收到此错误。我哪里错了?

function request($url, $data, $method)
{
    $curlSession = curl_init();

    $headers = [
    'Authorization: Basic ' . 'REDACTED'
    ];

    // Set the URL
    curl_setopt($curlSession, CURLOPT_URL, $url);
    curl_setopt($curlSession, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($curlSession, CURLOPT_HEADER,1);

    switch ($method) {
        case 'POST':
            curl_setopt($curlSession, CURLOPT_POST, 1);
            curl_setopt($curlSession, CURLOPT_POSTFIELDS, $data);
        case 'PUT':
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
            curl_setopt($curlSession, CURLOPT_POSTFIELDS, $data);
    }

    // Return it direct, don't print it out
    curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, 1);
    // Set correct port
    curl_setopt($curlSession, CURLOPT_PORT, 80);
    // This connection will timeout in 30 seconds
    curl_setopt($curlSession, CURLOPT_TIMEOUT, 30);


    // Disable SSL Checking as not working
    curl_setopt($curlSession, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curlSession, CURLOPT_SSL_VERIFYHOST, false);

    curl_setopt($curlSession, CURLINFO_HEADER_OUT, true);

    // Send the request and store the result in an array
    $rawResponse = curl_exec($curlSession);

    // Check that a connection was made
    if (curl_error($curlSession)) {
        $info = curl_getinfo($curlSession);
        $curlError = curl_error($curlSession);

        // Close the cURL session
        curl_close($curlSession);

        print_r($info);
        print($curlError);

        // If it wasn't...
        return false;
    }


    $info = curl_getinfo($curlSession);

    $httpStatus = curl_getinfo($curlSession, CURLINFO_HTTP_CODE);

    // Close the cURL session
    curl_close($curlSession);

    return $rawResponse;
}

【问题讨论】:

  • 感谢您的评论 @jww ,我不完全理解您的意思,我没有使用 SSH,我只是尝试对带有 https 前缀的 URL 的 curl 请求,我收到此错误。此评论与此有关吗?
  • 我明白了,这是我的简介中的一个问题,我现在将进行编辑
  • 服务器的 URL 是什么?发布openssl s_client -connect <server>:<port> 的结果。如果遇到任何验证错误,请不要担心。
  • @jww 我收到这条消息:getaddrinfo: Servname not supported for ai_socktype
  • 您使用的是 HTTP 还是 HTTPS 代理?如果是这样,你可以取消它或避免它吗?

标签: php curl ssl error-handling openssl


【解决方案1】:

尝试添加:

curl_setopt($curlSession, CURLOPT_SSLVERSION, 3);  // FIX SSL23_GET_SERVER_HELLO error

https://sourceforge.net/p/curl/bugs/1037

【讨论】:

  • 谢谢,但这没有帮助
  • 它解决了我的分段错误问题,谢谢! :)
猜你喜欢
  • 2017-03-08
  • 2013-04-14
  • 2021-12-07
  • 1970-01-01
  • 2021-01-02
  • 1970-01-01
  • 2019-06-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多