How long of a URL can Internet Explorer 9 take?
Past versions of Internet Explorer croaked o开发者_如何学JAVAn web addresses longer than 2,083 characters (see http://support.microsoft.com/kb/208427). Meanwhile, Firefox, Opera, and Safari can handle at least 80,000.
Version 9 brings many improvements. Is URL length is one of them?
Not the most precise answer, but it looks like 2083 characters in the address bar and 5165 characters when following a link.
(Not official in any way, just plugged a URL with 41,000 chars into a test HTM file and used Javascript to query the URL length.)
Update:
To reproduce the test, create an HTML file with an anchor element whose HREF attribute is 6000 characters long. Open the file in your browser and click the link. Then pop open the console and check window.location.href.length
.
Following this procedure in IE9 today, it reports the length as 5165 characters. If I load the same URL manually through the address bar, it reports 2083 characters.
For what it's worth, IE seems to truncate the URL before sending the request. If I put a URL of 24,000 characters in the anchor's HREF attribute, IE will follow the link but the resulting page reports a url length of 5165 characters. Following the same link in Chrome results in a HTTP 414 response from my test server.
I get 5120 characters in a url for internet explorer 9.
By no means a definitive test but the following demonstrates a quick check for url length of a href attribute in an anchor tag.
<html>
<head>
<script type="text/javascript">
function init() {
var anchor = document.getElementById('anc');
var valid = true;
var url = 'http://google.com/?search=';
var count = url.length;
while(valid) {
url = url + '1';
anchor.href = url;
count++;
valid = anchor.href == url;
if(count > 100000) {
alert('Test reached 100,000, stopping...');
valid = false;
}
}
alert('Complete, count = ' + count);
}
</script>
</head>
<body onload="init()">
<a id="anc" href="http://google.com/">Test</a>
</body>
</html>
I wrote this test that keeps on adding 'a'
to parameter until browser fails
C# part:
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult ParamTest(string x)
{
ViewBag.TestLength = 0;
if (!string.IsNullOrEmpty(x))
{
System.IO.File.WriteAllLines("c:/result.txt",
new[] {Request.UserAgent, x.Length.ToString()});
ViewBag.TestLength = x.Length + 1;
}
return View();
}
View:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
var text = "a";
for (var i = 0; i < parseInt(@ViewBag.TestLength)-1; i++) {
text += "a";
}
document.location.href = "http://localhost:50766/Home/ParamTest?x=" + text;
});
</script>
I added additional limits to IISExpress applicationhost.config
and web.config
setting maxQueryStringLength="32768"
.
also Added to config
<headerLimits>
<add header="Content-type" sizeLimit="32768" />
</headerLimits>
which didn't help at all, Finally decided to use fiddler to remove referer from header.
static function OnBeforeRequest(oSession: Session) {
if (oSession.url.Contains("localhost:50766")) {
oSession.RequestHeaders.Remove("Referer");
}
Which did nicely.
On IE9 I got
Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
4043
精彩评论