30
votes

Past versions of Internet Explorer croaked on 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?

3
Belongs on superuser.comdogbane
@fahd no it doesn't - it's essential info for web developersPekka
Length is not all that matters... it's about how you can use it - servers may have a significantly smaller limit to protect against some exploits and unauthorized intrusion.Arc
@Archimedix absolutely. I'm not saying it's a good thing to go too far beyond a few kilobytes in URL length. But knowing where IE9's limits are is a legitimate thing to ask.Pekka
IE9 has various limits (address bar, A HREF, Location header, etc). URLs under 2083 characters will work everywhere. Longer URLs can be resolved and navigated, but cause assorted problems (e.g. results will not be cached) and should be avoided if at all possible.EricLaw

3 Answers

18
votes

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.

10
votes

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>
1
votes

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