$http.post doesn't work well with Tomcat Java Servlets

1,145 views
Skip to first unread message

Vignesh Bhaskar

unread,
Jun 8, 2013, 11:54:16 AM6/8/13
to ang...@googlegroups.com

Can someone help me? I am using $http.post and posting the data as a json object to my Java servlet residing in tomcat. When i parse my parameters using getParameter, it returns only NULL.

The request is successful if i use $.ajax post. I am using $http.post because i need to use the $scope object in my call back

Carlos Campos Coelho

unread,
Sep 17, 2013, 9:19:59 AM9/17/13
to ang...@googlegroups.com
We were facing the same problem here.

In our scenario, we had to do two things:

1. Add the following line to the $http object:
     headers: {'Content-Type': 'application/x-www-form-urlencoded'}

2. Use POST method instead of GET
    method: 'POST'

So in the end, we came up with something like this:

myData = {"Email": "te...@teste.com.br",
                "Password": "123456"};
$http({
      method: 'POST',
      url: 'Login',
      data: myData,
      headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function (data) {
      alert(data);
}).error(function () {
      alert("login error");
});

Bernard Choi

unread,
Sep 17, 2013, 3:33:04 PM9/17/13
to ang...@googlegroups.com
I encountered a similar problem, and the following resource helped me.

Christian Ballarin Gomez

unread,
Apr 3, 2016, 4:06:18 PM4/3/16
to AngularJS

I had the same problem, you could solved this error finally?

Thanks,


Christian
Reply all
Reply to author
Forward
0 new messages