\http\client\Request - set cookies from http response

Wednesday, November 4, 2015

I use pecl_http 2.xx library to do HTTP requests from PHP scripts.
The problem is that i cannot correctly re-send cookies supplied by server on a new response.



My code:



$request = new \http\client\Request("GET", "http://1", $custom_headers);
$client = new \http\client();
$client->enqueue($request)->send();
$re = $client->getResponse($request);

$cookies = $re->getCookies();

$request = new \http\client\Request("GET", "http://2", $custom_headers);
$client = new \http\client();
$client->enqueue($request)->send();
$re = $client->getResponse($request);


I have tried passing cookies as array to setOptions() (cookies key), using \http\client\request::setCookies() but nothing seems to work - cookies are not sent with second request.



I have also tried using one client instance for two requests but this did not help, cookies are not re-sent.



source code of this library seem to be bad-written and not pretty to solve my problem.



Documentation lacks samples on keeping cookies between requests.



Thanks for suggestions

0 comments:

Post a Comment