Tôi đang cố viết một mô-đun tài nguyên AngularJS sẽ đăng một số dữ liệu lên máy chủ. Loại nội dung mặc định có vẻ là "application/xml". Tôi đang cố ghi đè loại nội dung thành "application/x-www-form-urlencoded". Khi thực hiện một http.post bình thường() tôi có thể thiết lập kiểu nội dung và khi tôi kiểm tra Firebug, tôi có thể thấy nó được đặt chính xác. Khi tôi sử dụng phương thức POST của tài nguyên, tôi không thể thay đổi kiểu nội dung từ mặc định. Tôi nghĩ rằng tôi đang làm nó theo cách mô tả documentation.AngularJS tài nguyên không đặt 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'}});
}
}
Bất kỳ ý tưởng hoặc ví dụ về cách để có được một nguồn tài nguyên AngularJS để đăng bài có nội dung kiểu khác nhau sẽ được nhiều đánh giá cao.