Limit for URL length for “rundll32 url.dll,FilePro

2019-04-10 07:01发布

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?

标签: java windows url
4条回答
做自己的国王
2楼-- · 2019-04-10 07:11

You will be running up against this operating system/browser specific maximum URL length problem:

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)...

查看更多
再贱就再见
3楼-- · 2019-04-10 07:13

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?

查看更多
迷人小祖宗
4楼-- · 2019-04-10 07:20

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.

查看更多
对你真心纯属浪费
5楼-- · 2019-04-10 07:37

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"});

查看更多
登录 后发表回答