以下工作正常,但我认为这会修改 $httpProvider 全局,这不是我想要的。
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)
}
}
反正有这样做吗?
...
.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;
})
“headers”参数似乎被忽略了。请求仍然
Content-Type:application/json;charset=UTF-8
我的标头值可以吗?