tags:

views:

626

answers:

4

What is the maximum length URL?

This is may be handset dependent; on a desktop, it is definitely browser dependent, as discussed in this question.

I am interested in specifications or references as much as empirical data.

My particular usecase is passing a very long (about 1600 character) URL to a MIDlet.platformRequest(String url), which is failing. The majority of the URL (some 1575 characters) is query.

Are there any other considerations for passing very long URLs about (e.g. mobile proxies and gateways truncating the URL)?

+1  A: 

According to the HTTP spec, you can rely on at least 255 characters, but beyond that it is browser specific. For example, IE limits the path part of the URL to 2048 characters, according to various sources, and Apache apparently complains about URLs > ~4000 characters.

Source: WWW FAQs: What is the maximum length of a URL?

I could not find any references to a URL limits for J2ME browsers.

UPDATE: "In the field of mobile browsing, URL limitation can be much lower. Many handsets still don’t support URLs longer than 128, 256 or 512 characters, in particular WAP devices (as opposed to devices carrying a full blown HTTP browser)."

Source: Maximum URL Length Web Analytics

Stephen C
Thanks. I reviewed this link while looking at the question I referenced. It makes no mention of mobile handsets.
jamesh
Second link ("Just another weblog") asserts this, without any sources. Unfortunately, this doesn't really answer the question. I appreciate your efforts.
jamesh
@jamesh: Honestly, I think there is unlikely to be a definitive answer. There do not appear to be any standards (apart from HTTP), and in the absence of any standard, handset browsers may limit the URL according to whatever the manufacturer thinks is best.
Stephen C
A: 

As @Stephen C pointed out, you can only count on the first 255 characters making it through. Can you modify your application to use a POST method instead? There is no limit to the amount of data that can be sent in a POST transaction.

pkaeding
Unfortunately, I am not in control of the server, so cannot change the method used to connect. I do not have a choice of service providers either.
jamesh
@jamesh: That's unfortunate, because using POST and restricting yourself to small URLs are your only real options, AFAIK.
Stephen C
A: 

Short answer: it depends, but probably long enough.

Long answer, following investigation on SonyEricsson J2ME emulator (WTK 2.2.4), a K610i, and Samsung U700V.


Empirically testing: from the emulator, the platformRequest() passes the URL straight to the desktop browser (Firefox in this case).

http://test.example.com/?q=2048xxxxxxxxxxxxxxxxxxxxxxxxxxxx... xxxxxxxxxxxxxxxxxx2048

Looking at the logs of a test server, we see we can pass through very long URLs from the emulator to the desktop to the server.

On a device (in this case, a SonyEricsson K610i, user agent: "SonyEricssonK610i/R1CB Browser/NetFront/3.3 Profile/MIDP-2.0 Configuration/CLDC-1.1") can handle at least a URL of at least 3072 characters (upper bound c.3800).

On a second device Samsung U700V, user agent: "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 MG(Novarra-Vision/7.3)", the lower bound for URL length was 2048, but upper bound was less than 3072. Note that this could be a problem with Novarra transcoder, which has been known to (at least) re-write user-agent strings.

Without the Novarra transcode (switching networks), the U700V has a user agent "SAMSUNG-SGH-U700-Vodafone/BUGK1 SHP/VPP/R5 NetFront/3.4 Qtv5.3 SMM-MMS/1.2.0 profile/MIDP-2.0 configuration/CLDC-1.1", and has a lower bound of 3072 chars.


This effectively ends my interest in the answer to this question, as this empirical testing invalidates my theory that an upper bound on URL length is causing my problem.

However, for completeness, I will include a potential cause of my problem:

The URL needed to connect has at least two query parameters. The ampersands separating the queries seem to confuse the emulator.

The emulator silently drops the second parameter.

On the Samsung, without a second parameter, the browser connects, but the long parameter is corrupted or missing.

On the K610i when a second parameter is used, the browser does not start properly.

jamesh
A: 

Microsoft Internet Explorer (Browser) Microsoft states that the maximum length of a URL in Internet Explorer is 2,083 characters, with no more than 2,048 characters in the path portion of the URL. In my tests, attempts to use URLs longer than this produced a clear error message in Internet Explorer. Firefox (Browser) After 65,536 characters, the location bar no longer displays the URL in Windows Firefox 1.5.x. However, longer URLs will work. I stopped testing after 100,000 characters. Safari (Browser) At least 80,000 characters will work. I stopped testing after 80,000 characters. Opera (Browser) At least 190,000 characters will work. I stopped testing after 190,000 characters. Opera 9 for Windows continued to display a fully editable, copyable and pasteable URL in the location bar even at 190,000 characters. Apache (Server) My early attempts to measure the maximum URL length in web browsers bumped into a server URL length limit of approximately 4,000 characters, after which Apache produces a "413 Entity Too Large" error. I used the current up to date Apache build found in Red Hat Enterprise Linux 4. The official Apache documentation only mentions an 8,192-byte limit on an individual field in a request. Microsoft Internet Information Server The default limit is 16,384 characters (yes, Microsoft's web server accepts longer URLs than Microsoft's web browser). This is configurable. Perl HTTP::Daemon (Server) Up to 8,000 bytes will work. Those constructing web application servers with Perl's HTTP::Daemon module will encounter a 16,384 byte limit on the combined size of all HTTP request headers. This does not include POST-method form data, file uploads, etc., but it does include the URL. In practice this resulted in a 413 error when a URL was significantly longer than 8,000 characters. This limitation can be easily removed. Look for all occurrences of 16x1024 in Daemon.pm and replace them with a larger value. Of course, this does increase your exposure to denial of service attacks. Recommendations Extremely long URLs are usually a mistake. URLs over 2,000 characters will not work in the most popular web browser. Don't use them if you intend your site to work for the majority of Internet users .

When you wish to submit a form containing many fields, which would otherwise produce a very long URL, the standard solution is to use the POST method rather than the GET method:

...

The form fields are then transmitted as part of the HTTP transaction body, not as part of the URL, and are not subject to the URL length limit. Short-lived information should not be stored in URLs.

As a rule of thumb, if a piece of information isn't needed to regenerate the same page as a result of returning to a favorite or bookmark, then it doesn't belong in the URL. The Bookmark Problem In very rare cases, it may be useful to keep a large amount of "state" information in a URL. For instance, users of a map-navigating website might wish to add the currently displayed map to their "bookmarks" or "favorites" list and return later. If you must do this and your URLs are approaching 2,000 characters in length, keep your representation of the information as compact as you can, squeezing out as much "air" as possible. If your field names take up too much space, use a fixed field order instead. Squeeze out any field that doesn't really need to be bookmarked. And avoid large decimal numbers - use only as much accuracy as you must, and consider a base-64 representation using letters and digits (I didn't say this was easy).

In extreme cases, consider using the gzip algorithm to compress your pretty but excessively long URL. Then reencode that binary data in base64 using only characters that are legal in URLs. This can yield a 3-4x space gain, at the cost of some CPU time when you unzip the URL again on the next visit. Again, I never said it was easy!

An alternative is to store the state information in a file or a database. Then you can store only the identifier needed to look up that information again in the URL. The disadvantage here is that you will have many state files or database records. Some of which might be linked to on websites run by others. One solution to this problem is to delete the state files or database records for the URLs that have not been revisited after a certain amount of time.

bala
-1 for a poorly formatted copypaste and doing as if it are your own words without mentioning the original sources (which are already linked in Stephen's answer).
BalusC