0

I'm trying to call a webservice that requires me to pass a JSON object to it. Though I'm not sure whether I'm doing it right. My service does the following:

this.updateAddressDetails = function (address, personId) {

    var url = 'http://213.456.123.456:8080/Address?' +
    'action=updateAddress' +
    '&personId=' + personId +
    '&address=' + JSON.stringify(address);

    return $http.get(url);

  }

But I get the following error server side (I'm using Java Servlets):

Error parsing HTTP request header

Which leads me to assume that I'm not passing the JSON to the server the correct way. Any tips?

4
  • Does your requestServlet support JSON format? You use Spring MVC or other framework on the server side? Commented Oct 28, 2015 at 13:55
  • Just normal vanilla servlets. I'm trying to get the JSON in the request by going 'request.getParameter("address")' and then serializing it to a Java POJO (Addres) by using Gson. Commented Oct 28, 2015 at 13:57
  • verify the request header in your browser, maybe there are some special caracter like '&' in your address? Commented Oct 28, 2015 at 14:01
  • why not post this rather than put it in a get? Commented Oct 28, 2015 at 14:17

1 Answer 1

1

Try something like this if your are working with angular JS:

$scope.myFunc = function() {

// Simple POST request example (passing data) :
$http.post("/createProject/"+ id +"", {
    projectTitle: pTitle,
    userID      : id
}).
success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available

    console.log("project created");
    console.log("this is the response data " + data);
}).
error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.