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)
source to share
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).
source to share