简体   繁体   English

$ http.post-请求标头字段Access-Control-Allow-Headers不允许授权

[英]$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不允许进行授权。

  1. Is putting the Auth base64 inside the headers a right way? 将Auth base64放在标头中是否正确?
  2. Is this the server's problem or am I doing something wrong? 这是服务器的问题还是我做错了什么?
  3. Is there any other way to test the credentials? 还有其他方法可以测试凭据吗?
  4. Is there any other server where I can test Auth? 还有其他可以测试Auth的服务器吗? I found https://httpbin.org/ but it only supports HTTP GET 我找到了https://httpbin.org/,但它仅支持HTTP GET

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.

相关问题 无法在POST Ajax请求中发送授权令牌-出现错误-Access-Control-Allow-Headers不允许请求标头字段authToken - Cannot send Authorization Token in POST Ajax request - getting error - Request header field authToken is not allowed by Access-Control-Allow-Headers 请求标头字段Access-Control-Allow-Headers在预检响应中不允许使用Access-Control-Allow-Headers - Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response Laravel API,请求标题字段在飞行前响应中不允许Access-Control-Allow-Headers进行授权 - Laravel API, Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response 设置请求标头时,在飞行前响应错误中,Access-Control-Allow-Headers不允许请求标头字段授权 - Request header field Authorization is not allowed by Access-Control-Allow-Headers in preflight response error while set request header 飞行前响应中的Access-Control-Allow-Headers不允许请求标头字段Access-Control-Request-Methods - Request header field Access-Control-Request-Methods is not allowed by Access-Control-Allow-Headers in preflight response 仅限Safari:访问标头字段Cache-Control不受Access-Control-Allow-Headers的限制 - Safari Only: Request header field Cache-Control is not allowed by Access-Control-Allow-Headers 预检响应中的 Access-Control-Allow-Headers 不允许 XMLHttpRequest 请求标头字段 postman-token - XMLHttpRequest Request header field postman-token is not allowed by Access-Control-Allow-Headers in preflight response 飞行前响应中的Access-Control-Allow-Headers不允许请求标头字段kbn-version - Request header field kbn-version is not allowed by Access-Control-Allow-Headers in preflight response 错误:Access-Control-Allow-Headers 不允许请求标头字段 Content-Type - Error :Request header field Content-Type is not allowed by Access-Control-Allow-Headers XMLHttpRequest无法加载请求标头字段Content-Type是Access-Control-Allow-Headers不允许的 - XMLHttpRequest cannot load Request header field Content-Type is not allowed by Access-Control-Allow-Headers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM