Trying to get the header authorization key in controller for making an API. Request is making from fiddler.
$headers = apache_request_headers();
And the $header contains an array.
Array ( [User-Agent] => Fiddler [Host] => localhost:8000 [Content-Length] => 102 [Authorization] => TestKey )
If am trying like this to fetch the Authorization , its throwing error.
$header['Authorization]
Error :
Undefined index: Authorization
Tried many ways to get the authorization, but not working anything. Is there any way to fetch this?
A- Get Laravel Bearer token: * Get the bearer token from the request headers. So you should just invoke this method to get the bearer token: $token = $request->bearerToken(); And then get what you expect.
To send a GET request with a Bearer Token authorization header, you need to make an HTTP GET request and provide your Bearer Token with the Authorization: Bearer {token} HTTP header.
To get headers from the request you should use the Request class
public function yourControllerFunction(\Illuminate\Http\Request $request) { $header = $request->header('Authorization'); // do some stuff }
See https://laravel.com/api/5.5/Illuminate/Http/Request.html#method_header
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With