如何重定向到带有标题的外部网址?

问题描述 投票:0回答:1

我如何有一个坐在A服务器上的应用程序,我想允许用户使用用户信息的标题到达B服务器中的另一个应用程序。我做了一些尝试,但我没有在B服务器获得标头。我怎么能实现那个?

以下是我尝试的代码: -

return redirect()->away($apiUrl)->header('x-api-token', $token);

$client = new Client();
        $request = $client->request('get', $apiUrl, [
            'headers' => [
                'x-api-user-token' => $userToken
            ]
        ]);

有没有办法让我重定向到带有标题的外部网址?

laravel
1个回答
1
投票

您可能想尝试Laravel提供的帮助方法,它对我来说就像一个魅力。

return redirect('http://external.url/', 302, [
    'custom-header' => 'custom value'
])

如果您想查看源代码,请参阅/vendor/laravel/framework/src/Illuminate/Foundation/Helpers.php

/**
 * Get an instance of the redirector.
 *
 * @param  string|null  $to
 * @param  int     $status
 * @param  array   $headers
 * @param  bool    $secure
 * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
 */
function redirect($to = null, $status = 302, $headers = [], $secure = null)
{
    if (is_null($to)) {
        return app('redirect');
    }

    return app('redirect')->to($to, $status, $headers, $secure);
} 
© www.soinside.com 2019 - 2024. All rights reserved.