繁体   English   中英

如何将标头设置为$ http.post方法AngularJS 1.3.5?

[英]How to set header to the $http.post method AngularJS 1.3.5?

我编写了一个REST Web服务,为避免我的Java代码出现错误,该错误是:与MIME媒体类型兼容的已注册消息正文阅读器,我必须在$ http.post中添加一个“ Content-Type”:“ application” / x-www-form-urlencoded”或“ Content-Type”:“ application / json”。 我使用的是Angularjs 1.3.5,每当我尝试添加标头{content-type ....}时,我都失败了。 我该怎么做才能解决我的问题?

 $scope.save = function(url,data) { var data_stack = $scope.stack; $http.post(url, data_stack) .then( function(response){ }, function(response){ }); } 
 <form ng-submit="save()"> <input ng-model="stack"></input> <button type="submit">Save</button> </form> 

var req = {
 method: 'POST',
 url: 'http://example.com',
 headers: {
   'Content-Type':'application/x-www-form-urlencoded' 
   // or  'Content-Type':'application/json'
 },
 data: { test: 'test' }
}

$http(req).then(function(){...}, function(){...});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM