[英]Request header field Authorization is not allowed
I have an Laravel based API on my Server.我的服务器上有一个基于 Laravel 的 API。 And I try to access this api from an AngularJS Frontend.我尝试从 AngularJS 前端访问这个 api。 Unfortunately this error shows up.不幸的是,这个错误出现了。
Where do I have to add the configuration to allow the Authorization Header?我必须在哪里添加配置以允许授权标头? I tried to find a solution but couldn't manage to solve it.我试图找到解决方案,但无法解决。
I tried to insert it in the httpd.conf
and in the .htaccess
of the Angular frontend but unfortunately it didn't work:我试图将它插入到httpd.conf
和 Angular 前端的.htaccess
中,但不幸的是它没有工作:
Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
If your server is using Apache, add the following snippet to your api's respective .htaccess file:如果您的服务器使用 Apache,请将以下代码段添加到您的 api 各自的.htaccess文件中:
<IfModule mod_headers.c>
Header set Access-Control-Allow-Headers "Authorization"
</IfModule>
in the above snippet, we are asking Apache to allow Authorization
header:在上面的代码段中,我们要求 Apache 允许Authorization
标头:
Header set Access-Control-Allow-Headers "Authorization"
you can add multiple headers
in one line, like this, but keep in mind that it's advised to only allow the headers required by your app .您可以像这样在一行中添加多个headers
,但请记住,建议仅允许您的应用程序所需的标题。
Header set Access-Control-Allow-Headers "Authorization, X-Requested-With"
In a related note, people often need to allow cross-origin request (also known as Cross-Origin Resource Sharing or CORS).在相关说明中,人们通常需要允许跨域请求(也称为跨域资源共享或 CORS)。 The following snippet allows cross requests from https://example.com
origin:以下代码段允许来自https://example.com
源的交叉请求:
Header set Access-Control-Allow-Origin "https://example.com"
or you might use "*"
to allow requests from all origins: Not Recommended或者您可以使用"*"
来允许来自所有来源的请求:不推荐
Header set Access-Control-Allow-Origin "*"
<IfModule mod_headers.c>
# To allow headers
Header set Access-Control-Allow-Headers "Authorization"
# to allow cross origin request from https://example.com
Header set Access-Control-Allow-Origin "https://example.com"
</IfModule>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.