4

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();
Finwe
  • 6,372
  • 2
  • 29
  • 44
Jiten Shahi
  • 41
  • 2
  • 7

1 Answers1

4

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.

Alexey Shokov
  • 4,775
  • 1
  • 21
  • 22