[英]$http.post - Request header field Authorization is not allowed by Access-Control-Allow-Headers
I'm using angular js. 我正在使用angular js。 I have a form where I'm asking the user to enter URL Basic Auth details ie, username and password for HTTP POST (like PostMan)
我有一个表单,要求用户输入URL基本身份验证详细信息,即HTTP POST的用户名和密码(如PostMan)
I need to check whether the credentials work or not. 我需要检查凭据是否有效。
I came up with the following code: 我想出了以下代码:
$http({method: 'POST', url: $scope.serviceConfig.url, headers: {
'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}
})
.success(function(res)
{
console.log(res);
})
.error(function(res)
{
console.log(res);
});
I get the following error: 我收到以下错误:
cannot load https://posttestserver.com/post.php .
无法加载https://posttestserver.com/post.php 。 Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response.
请求标头字段在飞行前响应中,Access-Control-Allow-Headers不允许进行授权。
You have indeed set the authorization header in the correct way. 您确实已经以正确的方式设置了授权标头。 However, postservertest.com has prohibited that header from being used via
Access-Control-Allow-Headers
: 但是,postservertest.com禁止通过
Access-Control-Allow-Headers
使用该标Access-Control-Allow-Headers
:
$ HEAD http://posttestserver.com
200 OK
Connection: close
Date: Wed, 06 Apr 2016 15:26:58 GMT
Server: Apache
Vary: Accept-Encoding
Content-Type: text/html; charset=UTF-8
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept
Access-Control-Allow-Origin: *
So in summary, your code is correct. 因此,总而言之,您的代码是正确的。 It is just the server unwilling to accept your request.
只是服务器不愿意接受您的请求。 You can try requestb.in .
您可以尝试requestb.in 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.