clat23

How to handle/follow Guzzle redirects within Laravel

Posted 4 months ago by clat23
$accessToken = env('ACCESS_TOKEN');

$client = new Client([
            'base_uri' => 'https://api.some-endpoint.com/',
            'allow_redirects' => true,
        ]);

$response = $client->get('https://api.some-endpoint.com/' , array(
            'headers' => ['Authorization' => 'Bearer ' . $accessToken],
        ));

dd($response->getBody());

// Result of above dd();
// Response {#1572 ▼
//  -reasonPhrase: "OK"
//  -statusCode: 200
//  -headers: array:12 [▶]
//  -headerNames: array:12 [▶]
//  -protocol: "1.1"
//  -stream: Stream {#1570 ▶}
// }

When I do not dd() the response, the user does not get redirected. How do I take the redirect URL form the $response so I can redirect the user?

Please sign in or create an account to participate in this conversation.