无法使用Slim Framework读取“Authorization”HTTP标头

I'm trying to send "Authorization" in the header of a GET request.

In the REST Server, I'm using Slim Framework, and I'm trying to read headers with:

$app->request()->headers()->all();

this perfectly works, but I can't see the "Authorization" field.

I tried to put a "test" field in the request and I can see it. How can I solve this?

I also tried with:

apache_request_headers();

but the result is not different.

If you are sending something else than valid HTTP Basic Authorization header, PHP will not have access to it. You can work around this by adding the following rewrite rule to your .htaccess file.

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]