The following works fine, but I am thinking this modifies the $httpProvider globally, which isn't what I want.
angular.module('SessionService', ['ngResource'])
.config(function($httpProvider){
$httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'
})
.factory('Login', function($resource){
var resource = $resource('/adminui/login',{},{
post:{
method:"POST",
isArray:false
},
});
return resource;
})
LoginCtrl = function($scope,Login) {
$scope.login = function(){
Login.post($.param({user:$scope.user.username,password:$scope.user.password}),$.noop,$.noop)
}
}
Is there anyway to do this instead?
...
.factory('Login', function($resource){
var resource = $resource('/adminui/login',{},{
post:{
method:"POST",
isArray:false,
headers:{'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} // ignored
},
});
return resource;
})
The "headers" parameter seems to be ignored. the request is still
Content-Type:application/json;charset=UTF-8
Is my value for headers ok?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…