3

I wrote a rest webservice and to avoid the error I got in my java code which is: The registered message body readers compatible with the MIME media type, I have to add to my $http.post a 'Content-Type': 'application/x-www-form-urlencoded' or 'Content-Type': 'application/json'. I am using Angularjs 1.3.5 and whenever I tried to add the headers {content-type.... }, I failed. What can I do exactly to solve my problem?

$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>

1 Answer 1

7
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(){...});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.