我如何有一个坐在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提供的帮助方法,它对我来说就像一个魅力。
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);
}