withCredentials AngularJS请求发布错误
我似乎无法发送$http.post身份验证请求。我的代码与此页上的解决方案匹配,但我通过浏览器控制台获得此错误withCredentials AngularJS请求发布错误,angularjs,Angularjs,我似乎无法发送$http.post身份验证请求。我的代码与此页上的解决方案匹配,但我通过浏览器控制台获得此错误 Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials. 这是代码的样子: $scope.authenticate = function (user, pass) { $http.pos
Credentials flag is 'true', but the 'Access-Control-Allow-Credentials' header is ''. It must be 'true' to allow credentials.
这是代码的样子:
$scope.authenticate = function (user, pass) {
$http.post(authUrl, {
username: user,
password: pass
}, {
withCredentials: true
})
}
我对angularJS还是个新手,但我阅读了另一个网站上关于设置自定义标题的帮助,因此我可以修复关于标题的错误消息。我尝试使用:
$httpProvider.defaults.headers.post = { 'Access-Control-Allow-Credentials' : 'true' }
但如果没有$httpProvider未定义的错误,我似乎无法正确执行。我把它放在$http.post调用之上,也放在控制器的函数范围内:
.controller("authCtrl", function($scope, $http, authUrl, $httpProvider) {
有什么想法吗?,您只能在配置阶段与提供商进行交互
app.config(["$httpProvider", function ($httpProvider) {
$httpProvider.defaults.withCredentials = true;
});
必须在服务器上设置访问控制允许凭据。进一步阅读:
您是否尝试过$httpProvider.defaults.withCredentials=true;?我刚试过。我得到了相同的未定义错误:$httpProvider未定义我得到了相同的错误。此布尔值似乎已设置为true,但标头未更新。凭据标志为“true”,但“访问控制允许凭据”标头为。必须为“true”才能允许凭据。