XMLHttpRequest fails when outgoing Content-Length exceeds 3508 bytes. Why?
UPDATE: I've moved on, not looking for an answer
UPDATE: See the last update below.
I'm doing a POST request using JQuery's jQuery.ajax()
function and when the outgoing Content-Length
exceeds 3508 bytes something goes wrong and no response is returned. As long as the Content-Length remains under 3509 bytes everything will work fine.
Here's some other things I've noticed:
If I change the method from POST to GET everything works fine, but because a URL has a (browser-specific) maximum length I don't think I can just do this (for example the maximum length is 2,083 characters for Internet Explorer).
When I do a normal non-XMLHttpRequest form POST everything works fine too (even with a Content-Length far greater than 3508 bytes).
Firefox (3.6.12) will still call the success handler with data being "undefined" while Internet Explorer (8) will instead call the error handler with textStatus being "error" and errorThrown "undefined".
Note that on the "server side" I'm running the ASP.NET Development Server and using ASP.NET MVC 1.0.
Here's basically what I'm doing:
$.ajax({
type: "POST",
url: "", // A resource on localhost
// The following string results in a Content-Length of 3509 bytes
data: "---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------开发者_JAVA技巧--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------",
success: function(response) {
alert(response);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus + " " + errorThrown);
},
dataType: "json"
});
Any ideas?
UPDATE:
Here are the request headers for a failed request (there is no response):
POST /WPA/BerekenEindcijfer HTTP/1.1
Host: localhost:4387
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729)
Accept: application/json, text/javascript, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Referer: http://localhost:4387/WPA
Content-Length: 3509
UPDATE: I published the application to IIS (5.1) and the problem didn't occur there and weirdly enough the problem now also doesn't occur anymore using the ASP.NET Development Server. For some reason two new headers appear in the request (though I'm not sure if they have any impact):
Pragma: no-cache
Cache-Control: no-cache
I'm still baffled as to what is/was going on.
Have you tried changing this in your web.config.:
<scripting>
<webServices>
<jsonSerialization maxJsonLength="5000"/>
</webServices>
</scripting>
Configuring JSON Serialization
精彩评论