Error from Mongrel: “HTTP element REQUEST_PATH is longer than the 1024 allowed length”
Pregunta
I have a website that runs queries on the server, which is running Mongrel. The query syntax can get quite involved, and I just ran a query (HTTP request) that yielded this error.
All workarounds welcome.
EDIT: Here's the full ajax command:
$.ajax({
type: "POST",
url: '/parsequery/' + jsonQuery,
beforeSend: function(x) { // this is needed because otherwise jquery doesn't see the returned data as json
if(x && x.overrideMimeType) {
x.overrideMimeType("text/html");
}
},
datatype: 'json',
success: function(data, textStatus) {
if (parsedOK(data)) {
executeQuery(jsonQuery);
}
else {
handleFailedParse(data);
}
},
error: function(jaXHR, textStatus, errorThrown) {
alert("error sending request: " + textStatus)
}
});
Solución
You should use HTTP POST for that. Many server and browser implementations have tight limits on the query length, something around 1 kByte or 2 kBytes.
So instead of
<form action="http://www.example.org/foo" method="get">
you should do
<form action="http://www.example.org/foo" method="post">
And in case you do not do the requests via forms, you could use jQuery for instance:
$.post("/foo", {"param1": "foo", "param2": "bar"}, function(data) {
alert("post successful!");
});
See here for examples: http://api.jquery.com/jQuery.post/
Of course the server side needs to handle POST requests. But changing from GET to POST on the server side is should be from a programming point of view trivial.