problems using cURL to access https

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rory

    #1

    problems using cURL to access https

    I'm just starting to use cURL and having trouble accessing https pages.
    All I want to do at this stage is get an https page and display it,
    just to test the https get is working. However, I always get either a
    CURLE_OPERATION _TIMEOUTED (28) or CURLE_COULDNT_C ONNECT (7) error.
    I can see from phpinfo() that cURL and SSL are installed, as follows:
    CURL support enabled
    CURL Information libcurl/7.12.0 OpenSSL/0.9.6b zlib/1.1.4
    but my code that works fine for an http call doesn't work for an https
    call. Any suggestions on what I might be doing wrong or what might be
    stopping the call from working? I'm on a hosted site so I don't have
    command line access.
    PHP Version 4.3.10, running on linux & apache.

    here's the code I'm running:
    <?php
    $ch = curl_init();
    curl_setopt($ch , CURLOPT_URL, "https://myserviceall.co m/index.php");
    // any old https page
    curl_setopt($ch , CURLOPT_TIMEOUT ,10);
    $result = curl_exec ($ch);
    if (curl_error($ch )){
    print "<br>error #" . curl_errno($ch) . ": " . curl_error($ch) ;
    }
    curl_close ($ch);
    print $result;

    print "<br>end<br >";

    phpinfo();
    ?>

    Same code works fine for an http url.

    I've also tried calling curl_setopt( $ch, CURLOPT_SSLVERS ION, 2); since
    there was mention somewhere that might help, but same problem occurs.

    help greatly appreciated.

    - Rory

  • Chuck Anderson

    #2
    Re: problems using cURL to access https

    Rory wrote:
    [color=blue]
    >I'm just starting to use cURL and having trouble accessing https pages.
    > All I want to do at this stage is get an https page and display it,
    >just to test the https get is working. However, I always get either a
    >CURLE_OPERATIO N_TIMEOUTED (28) or CURLE_COULDNT_C ONNECT (7) error.
    >I can see from phpinfo() that cURL and SSL are installed, as follows:
    > CURL support enabled
    > CURL Information libcurl/7.12.0 OpenSSL/0.9.6b zlib/1.1.4
    >but my code that works fine for an http call doesn't work for an https
    >call. Any suggestions on what I might be doing wrong or what might be
    >stopping the call from working? I'm on a hosted site so I don't have
    >command line access.
    >PHP Version 4.3.10, running on linux & apache.
    >
    >here's the code I'm running:
    ><?php
    >$ch = curl_init();
    >curl_setopt($c h, CURLOPT_URL, "https://myserviceall.co m/index.php");
    >// any old https page
    >curl_setopt($c h, CURLOPT_TIMEOUT ,10);
    >$result = curl_exec ($ch);
    >if (curl_error($ch )){
    > print "<br>error #" . curl_errno($ch) . ": " . curl_error($ch) ;
    >}
    >curl_close ($ch);
    >print $result;
    >
    >print "<br>end<br >";
    >
    >phpinfo();
    >?>
    >
    >Same code works fine for an http url.
    >
    >I've also tried calling curl_setopt( $ch, CURLOPT_SSLVERS ION, 2); since
    >there was mention somewhere that might help, but same problem occurs.
    >
    >help greatly appreciated.
    >
    >- Rory
    >
    >
    >[/color]
    Try adding this option:

    curl_setopt($ch , CURLOPT_SSL_VER IFYPEER, FALSE);

    A tutorial that I found said it was necessary (and it worked for me).

    --
    *************** **************
    Chuck Anderson • Boulder, CO

    Integrity is obvious.
    The lack of it is common.
    *************** **************

    Comment

    Working...