Redirects

22 views
Skip to first unread message

Tim

unread,
Feb 27, 2014, 4:28:36 PM2/27/14
to guz...@googlegroups.com
Given the following code/psuedo-code....

$requests = array ( 'http://url1whichdoesnotredirect.com','http://url2.whichdoesredirect.com');

$responses = $this->client->send($requests);

$responses[0]['statuscode'] = "200";
$responses[1]['statuscode'] = "301"; //permanently moved

Responses[1] body is a small string of "...permanently moved...".

BUT if I trace the code the redirects do work for responses[1].  And, if I look at the history plugin the last response object has all the correct info. 

What needs to be done so that $responses = $this->client->send($requests) the second $response returns the redirected content? (And more appropriately what needs to be done so that when $responses[100] that any element in the $responses array contains the redirected content?)


Tim

unread,
Mar 12, 2014, 8:10:21 PM3/12/14
to guz...@googlegroups.com
Looks like setting

CURLOPT_FOLLOWLOCATION => true

in the curl options array for the guzzle client ($this->client) solved the issue.

Michael

unread,
Mar 20, 2014, 12:02:49 AM3/20/14
to guz...@googlegroups.com
Guzzle should handle redirects for you. Adding CURLOPT_FOLLOWLOCATION could potentially cause issues because Guzzle assumes that it is following redirects rather than cURL. It might work, but I don't recommend it.

If you can, please open an issue on the Guzzle 3 repo with a cURL verbose output and more information on how this can be reproduced.

Reply all
Reply to author
Forward
0 new messages