tags:

views:

2968

answers:

4

I have a long URL with tons of parameters that I want to open in the default browser from Java on a Windows system using

Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler "+url)

For short URLs like "http://www.google.com" this works fine. But for long URLs (say, 2000 characters), this simply does absolutely nothing at all: no exception or anything of the sort, it is simply ignored.

Is there a character limit a) for a Runtime.exec command or b) for the rundll32 url.dll command? If so, what is the limit?

+1  A: 

You will be running up against this operating system/browser specific maximum URL length problem: http://www.boutell.com/newfaq/misc/urllength.html

For "rundll32 url.dll" (i.e. Microsoft IE) you will be limited to 2,083 characters (including http://).

From where I sit you have two alternatives:

  1. Build (or use) a TinyURL-style service that turns your long-urls into short, redirected ones. However even here you are going to run into the same URL length issue, just within the browser itself rather than your Runtime() statement. e.g. The browser window would open, go to the short-URL which would perform the redirect to the long-URL and fail.

  2. Use a POST request and bury some or all of your URL parameters within it. Rather than using a GET call you can supply very long parameters within the body of an HTTP POST request. This would not be as simple as your example code. In fact this maybe quite tricky (or impossible) with the rundll32 url.dll combination (I am not familiar with it)...

David Harrison
A: 

It will also depend on the version of windows, because you may be exceeding the operating system's MAX_PATH length on the command line?

John Gardner
A: 

You could also try the Runtime.exec(String []) version, which you may have better luck with. Just take all your space seperated arguments and pass them in as seperate strings:

Runtime.getRuntime().exec(new String [] {"rundll32", "url.dll,FileProtocolHandler", "urlarg1", "urlarg2"});

James Van Huis
+1  A: 

As an aside, I would suggest using the cross platform Desktop.open() or Desktop.browse() instead of Windows only rundll32. This will give you an IOException if it can't open the write application.

jamesh