簡體   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