Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
326 views
in Technique[技术] by (71.8m points)

php - SSL Connection Error even when VERIFYPEER, VERIFYHOST disabled

I am at present building a script to fulfil some SSL curl requests, however I have had no luck in fulfilling these. All I receive from curl_error() is a simple "SSL Connection Error" string... This is not helpful at all. I have tried inserting a valid self-signed certificate, disabled verification entirely (as seen in the code below), and a million and one other configuration variances, but I consistently get this error. Where am I going wrong?

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try to add:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...