Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

irfanALIAzhari's avatar

Authorizarion header not exist at Api Endpoint

Hi, I trying to calling an Api with Authorization header. After dispatch the request, the authorization header does not exist.

Note: 
1. Through Postman everything work fine.
2. (The issue is) Authorizarion header missing after request dispatch via my application.

Please have a look at my code below.

//API Calling..
{
$request = ApiReq::create('/api/'.$endPoint, $method);
$request->headers->set('Authorization','Bearer '.session()->get('auth_token'));

//Authorization header exist in such request
dd($request->header());
}
Route::match(['get', 'post'], 'profile/{uid?}', function(Request $request){
    //Authorization header not exist in such request
    dd($request->header());
});

Do you have any idea to resolve the issue?

0 likes
2 replies
irfanALIAzhari's avatar

Look at the .htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    
    # Handle Authorization Header
    #RewriteCond %{HTTP:Authorization} .
    #RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    RewriteCond %{HTTP:Authorization} ^(.+)$
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    
    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
irfanALIAzhari's avatar

Have a look at some additional details

Project: Laravel Framework 5.8.36
Server: apache2
OS: Linux Ubuntu / 16.04
Note: I upgraded the project from Laravel 5.5 to 5.8 few week ago.

Please or to participate in this conversation.