2016-06-07 30 views
0

我寫了一個休息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; 
 
\t \t $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>

回答

3
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(){...}); 
+0

它的工作,謝謝! –

+0

這是我的榮幸:) –