How to make an https request using php Http_Request2 ()

I want to make an https request using the pear class http_request2 ($ url). I can make an http request, but not https. and the website facilitates both http and https. No problem with the server responding to https.

    require 'HTTP/Request2.php';
    $url = 'https://collegedb2.ferryfair.com';
    $r = new Http_Request2($url);
    $r->setMethod(HTTP_Request2::METHOD_POST);
    try {
        $response = $r->send();
    } catch (Exception $exc) {
        $es = $exc->getTraceAsString();
        $ets=$exc->__toString();
        $egc=$exc->getCode();
        $egl=$exc->getLine();
        $egm=$exc->getMessage();
        $egt=$exc->getTrace();
        $response = null;
    }
    $page = $response->getBody();
    echo $page;

      

this is msg error:

$egm=(string) Unable to connect to ssl://collegedb2.ferryfair.com:443. Error: stream_socket_client(): unable to connect to ssl://collegedb2.ferryfair.com:443 (Unknown error)

+3


source to share


3 answers


The comment for disabling certificate validation was the key for me.



$request = new HTTP_Request2('https://someserver.com/somepath/something',
    HTTP_Request2::METHOD_POST);

$request->setConfig(array(
    'ssl_verify_peer'   => FALSE,
    'ssl_verify_host'   => FALSE
));

      

+8


source


I got this problem. The fix (for me) was to use "curl" as an adapter, for example:

$request = new Http_Request2('https://whatever');
$request->setAdapter('curl');
$response = $request->send();

      

See also the SSL Options section at http://pear.php.net/manual/en/package.http.http-request2.config.php which says



Peer validation will most likely fail unless you explicitly provide the ssl_cafile and / or ssl_capath file, especially with a Socket adapter.

Presumably curl knows where to find the local CA file it needs to trust.

(PHP 5.4.38 with curl).

+4


source


HTTP_Request2 is absolutely capable of making HTTPS requests. There is probably a deeper error, eg. custom SSL certificate which is causing problems.

Install Wireshark and check what kind of error you are actually getting with it. Send it back.

0


source







All Articles