일부 데이터를 서버에 게시 할 AngularJS 자원 모듈을 작성하려고합니다. 기본 컨텐츠 유형은 "application/xml"입니다. 나는 content-type을 "application/x-www-form-urlencoded"로 바꾼다. 정상적인 $ http.post()를 수행 할 때 컨텐트 유형을 설정할 수 있으며 Firebug를 체크인 할 때 제대로 설정되었는지 확인할 수 있습니다. 리소스의 POST 메서드를 사용할 때 컨텐트 유형을 기본값에서 변경할 수 없습니다. 나는 documentation의 설명에 따라 그것을하고 있다고 생각합니다. AngularJS와 자원이 다른 콘텐츠 형식으로 게시하는 방법에 대한AngularJS 자원이 설정되어 있지 않습니다. Content-Type
var myApp = angular.module('myApp',['myResource']);
angular.module('myResource', ['ngResource']).factory('myResource', function($resource){
return $resource('/echo/json',{},{
add:{ method:'POST', params:{ foo:'1' }, headers:{'Content-Type':'application/x-www-form-urlencoded'} }
});
});
function MyCtrl($scope,$http,myResource) {
$scope.click = function() {
//This will make an ajax call with a content-type of application/xml
myResource.add();
//this will make an ajax call with a content-type of application/x-www-form-urlencoded
$http.post('/echo/json','foo=1',{'headers':{'Content-Type':'application/x-www-form-urlencoded'}});
}
}
어떤 아이디어 나 사례가 많이 주시면 감사하겠습니다.