I am executing a POST request with Angular JS against a Java servlet running on Google App Engine. The code works fine, unfortunately I've noticed that if one (or more) parameters are very long I get the following error:
Error: Length Required
POST requests require a Content-length header.
This is my Angular JS code:
app.controller('mycontroller', ['$scope', '$http', '$log', function($scope,$http,$log) {
this.myfunction = function() {
$http({
method: 'POST',
url: '/myservlet',
params: { method: 'my_method', param1 : $("#param1").val(), param 2: ... }
}).success(function(data) {
}).error(function(data) {
});
};
}
Param1, param2 etc are different fields, mostly textarea though. Any suggestion? Honestly I don't know what to do.
EDIT: I tried setting the Content-Length in the header myself but I get an error as I expected...
headers : { 'Content-Length' : 0 },
Refused to set unsafe header "Content-Length"
So basically, if I set the Content-Length the browser refuses to execute the call, if I don't set it then the server says it's required... What can I do?