以下工作正常,但我认为这会全局修改$ 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)
}
}
Run Code Online (Sandbox Code Playgroud)
反正这样做呢?
...
.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;
})
Run Code Online (Sandbox Code Playgroud)
"headers"参数似乎被忽略了.请求仍然是
Content-Type:application/json;charset=UTF-8
我的标题值是否正常?
angularjs ×1