Patrick Younes
Patrick Younes

Reputation: 139

HTTPS Requests error with HTTP_Request2 in PHP 5.4.12

I don't have any issues with using PEAR's HttpRequest2 for HTTP Requests, however this issue starts when I have an API in an HTTPS url; Do note that I'm using PHP 5.4.

<?php
// This sample uses the Apache HTTP client from HTTP Components (http://hc.apache.org/httpcomponents-client-ga/)
require_once 'HTTP/Request2.php';


$request = new HTTP_Request2('https://api.transavia.com/v3/routes/',
                             HTTP_Request2::METHOD_GET, array('use_brackets' => true));

$url = $request->getUrl();

// I tried removing SSL verification, hoping it would help, it did not.
$request->setConfig(array(
    'ssl_verify_peer'   => FALSE,
    'ssl_verify_host'   => FALSE
));

// Ignore first 2 Headers; those are tests from Postman, which work, meaning the APIKey and Variables are correct
$request->setHeader(array(
  'postman-token' => '2ab78460-4e01-de66-1b31-274362f34a3e',
  'cache-control' => 'no-cache',
  'apikey' => '24e555fe917a4762a6b462cbe177dcae'
));


$url->setQueryVariables(array(
    'Origin' => 'AMS',
    'Destination' => 'ACE'
));

// This will output a page with open bugs for Net_URL2 and HTTP_Request2
echo $request->send()->getBody();


?>

The error I would get is

( ! ) Fatal error: Uncaught HTTP_Request2_MessageException: in C:\wamp\pear\HTTP\Request2\Adapter\Socket.php on line 1020 aaaaaa; text-align: center; font-weight: bold;">Exception trace cccccc; width:20px; font-weight: bold;">#Function

style="text-align: center; background: #cccccc; font-weight: bold;">Location 0HTTP_Request2_Response->__construct('', true, Object(Net_URL2))C:\wamp\pear\HTTP\Request2\Adapter\Socket.php:1020 1HTTP_Request2_Adapter_Socket->readResponse()C:\wamp\pear\HTTP\Request2\Adapter\Socket.php:136 2HTTP_Request2_Adapter_ in C:\wamp\pear\HTTP\Request2\Response.php on line 215

Any sort of helpful feedback would be highly appreciated


Edit log: @twicejr; Error: Malformed response: HvTTP/1.1 200 OK

The "v" in "HvTTP" is constantly changing everytime I refresh. It switches between b,v,¥, etc..

Upvotes: 1

Views: 1078

Answers (0)

Related Questions