title: POST request returns 415 error
body: <p>I'm trying to call a POST request (using Jersey APi for REST) from an HTML form using AngularJS v 1.5.8. <br>
  I have an HTML form with a submit button that calls a REST serivce:</p>
  
  <pre><code>&lt;body ng-app="myApp" ng-controller="loginController"&gt;
  ......
  &lt;form name="myForm" nonvalidate ng-submit="login()"&gt;
  
  ......
  
  &lt;div
  class="col-md-4 col-md-offset-4 col-sm-4 col-sm-offset-3 col-xs-6 col-xs-offset-3"&gt;
  &lt;button type="submit" class="btn btn-default" ng-submit="login()"&gt;Submit&lt;/button&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is my loginController script:</p>
  
  <pre><code>var app = angular.module ("myApp", []);
  app.controller("loginController", function($scope, $http){
  
      $scope.username = "";
      $scope.password = "";
  
      $scope.login = function() {
  
          var transform = function(data) {
              return $.param(data);
          }
  
          $http(
                  {
  
                      url : 'http://localhost:8080/RestServices/services/user/add',
                      method : 'POST',
                      headers : {
                          'Content-Type' : 'application/x-www-form-urlencoded; charset=UTF-8'
                      },
  
                      transformRequest : function(data) {
                          return $.param(data);
                      },
                      data: { name:     $scope.username,
                              password: $scope.password }
  
                  }).success(function(response, status) {
                      $scope.data = response; //Assign data received to $scope.data
                  }
                  )
      }
  }
  )
  </code></pre>
  
  <p>And here is my simple REST post service:</p>
  
  <pre><code>@Path("user")
  public class UserResource {
  
      private TreeMap&lt;Integer, User&gt; userMap = new TreeMap&lt;Integer, User&gt;();
  
  
      @POST
      @Path("add")
      @Consumes({MediaType.APPLICATION_JSON})
  
      public Response addUser(User user) {
  
          int id = userMap.size();
          user.setId(id);
          userMap.put(id, user);
  
          ObjectMapper mapper = new ObjectMapper();
          String jsonString = "";
          try {
              jsonString = mapper.writeValueAsString(user);
          } catch (JsonProcessingException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              jsonString = null;
          }
  
          return Response.ok().entity(jsonString).build();
  
      }
  
  }
  </code></pre>
  
  <p>The POST request is called but returns a 415 error: <em>the server refused this request because the request entity is in a format not supported by the requested resource for the requested method.</em></p>