guzzle allow redirects false does not work

Viewed 4815

Guzzle not stopping data from Redirect:

The following guzzle request not preventing redirects always show status 200 while I have tried with postman it returns 302:

$response = $client->request(
    'GET', 
    $Url, 
    ['query' => $body], 
    [
        'headers' => [
            'Content-Type' => 'application/x-www-form-urlencoded'
        ]
    ], 
    ['allow_redirects' => FALSE]
);
$responseHomeNetworkAPI = $response;
echo $response->getStatusCode();
1 Answers

As I already said on GitHub, probably because you use request() method in a wrong way. All your three arrays should be combined into one:

$response = $client->request(
    'GET',
    $Url,
    [
        'query' => $body,
        'headers' => ['Content-Type'  => 'application/x-www-form-urlencoded'],
        'allow_redirects' => false
    ]
);

BTW, Content-Type: application/x-www-form-urlencoded makes no sense in a GET request.

Related