php - Guzzle cookies handling -
i'm building client app based on guzzle. i'm getting stucked cookie handling. i'm trying implement using cookie plugin cannot work. client application standard web application , looks it's working long i'm using same guzzle object, across requests doesn't send right cookies. i'm using filecookiejar
storing cookies. how can keep cookies across multiple guzzle objects?
// first request login works fine $cookieplugin = new cookieplugin(new filecookiejar('/tmp/cookie-file')); $client->addsubscriber($cookieplugin); $client->post('/login'); $client->get('/test/123.php?a=b'); // second request expect working, it's not... $cookieplugin = new cookieplugin(new filecookiejar('/tmp/cookie-file')); $client->addsubscriber($cookieplugin); $client->get('/another-test/456');
you creating new instance of cookieplugin
on second request, have use first 1 on second (and subsequent) request well.
$cookieplugin = new cookieplugin(new filecookiejar('/tmp/cookie-file')); //first request $client = new guzzle\http\client(); $client->addsubscriber($cookieplugin); $client->post('/login'); $client->get('/test/first'); //second request, same client // no need $cookieplugin = new cookieplugin(... $client->get('/test/second'); //third request, new client, same cookies $client2 = new guzzle\http\client(); $client2->addsubscriber($cookieplugin); //uses same instance $client2->get('/test/third');
Comments
Post a Comment