【发布时间】:2016-04-06 14:27:40
【问题描述】:
我正在使用角度 js。 我有一个表单,要求用户输入 URL 基本身份验证详细信息,即 HTTP POST 的用户名和密码(如 PostMan)
我需要检查凭据是否有效。
我想出了以下代码:
$http({method: 'POST', url: $scope.serviceConfig.url, headers: {
'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=='}
})
.success(function(res)
{
console.log(res);
})
.error(function(res)
{
console.log(res);
});
我收到以下错误:
无法加载https://posttestserver.com/post.php。请求头域 Access-Control-Allow-Headers 不允许授权 预检响应。
- 将 Auth base64 放入标头中是否正确?
- 这是服务器的问题还是我做错了什么?
- 还有其他方法可以测试凭据吗?
- 还有其他服务器可以测试 Auth 吗?我找到了https://httpbin.org/,但它只支持 HTTP GET
【问题讨论】:
标签: jquery angularjs http http-headers