4

i want to make a https request using pear http_request2($url) class. i am able to make http request but not https. and the website facilitate both http and https. No prob with 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 the error msg:

$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)

Necktwi
  • 2,483
  • 7
  • 39
  • 62
  • It seems the ssl certificate is not installed/configured correctly, when connecting i get the following error: ssl_error_rx_malformed_certificate (SSL3_GET_SERVER_CERTIFICATE:unable to find public key parameters) – stewe Apr 09 '12 at 03:24
  • u tried connecting https://collegedb2.ferryfair.com ?? it is only available on our local network. ssl certificate on server got installed correctly. problem is with http_request2 class, it is unable to make https requests. openssl is enabled in php, checked in phpinfo() – Necktwi Apr 09 '12 at 05:48

3 Answers3

7

The comment to disable certificate verification 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
));
Mr. Lee
  • 179
  • 1
  • 7
5

I experienced this problem. The fix (for me) was to use 'curl' as the adapter, for example :

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

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

Peer verification is likely to fail if you don't explicitly provide ssl_cafile and/or ssl_capath, especially with Socket adapter.

Presumably curl knows where to find a local CA file to trust.

(PHP 5.4.38 with curl).

David Goodwin
  • 4,184
  • 1
  • 22
  • 12
  • Ah, thanks for this one. Now I can stop worrying about rewriting all my requests with CURL. ;-) – Leo Mar 09 '15 at 13:44
0

HTTP_Request2 is absolutely able to make HTTPS requests. There is probably a deeper error, e.g. a custom SSL certificate that brings problems.

Install Wireshark and check which error you actually get with it. Post that back.

cweiske
  • 30,033
  • 14
  • 133
  • 194
  • thanq cweiske, for a while i've skipped solving this issue. the target web application is using self signed ssl certificate. i think i should install the certificate in my web application. i donno how to. i googled it a lot about it, finally gave up. i need help here. – Necktwi May 04 '12 at 07:49
  • you can either disable certificate verification - see the options in http://pear.php.net/manual/en/package.http.http-request2.config.php - or install the public certificate of the authority (CA) that signed the self-signed certificate. – cweiske May 04 '12 at 07:56
  • thanq. how abt using target web application's ssl certificate with ssl_local_cert or ssl_capath parameters. i didnt completely understand ssl_local_cert parameter, should it be given the file name of target web application's ssl certificate? – Necktwi May 04 '12 at 08:20
  • `require 'HTTP/Request2.php'; $url = 'https://collegedb2.ferryfair.com/lib/crap.html'; $r = new Http_Request2($url); $r-> setConfig(array("ssl_verify_peer"=>TRUE,"ssl_local_cert"=>"$root/ssl/collegedb2.ferryfair.com.cert"));` i am making this request from the same server.. – Necktwi May 04 '12 at 15:05
  • i got the target server certificate with me. I want to verify the certificate. if u succeed in verifying target please post it. – Necktwi May 29 '12 at 05:33