Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

guzzle allow redirects false does not work

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();
like image 769
Jiten Shahi Avatar asked Sep 13 '25 01:09

Jiten Shahi


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.

like image 172
Alexey Shokov Avatar answered Sep 15 '25 18:09

Alexey Shokov