windows “rundll32 url.dll,FileProtocolHandler”的 URL 长度限制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/242579/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:32:05  来源:igfitidea点击:

Limit for URL length for "rundll32 url.dll,FileProtocolHandler"?

javawindowsurl

提问by Epaga

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

我有一个包含大量参数的长 URL,我想在 Windows 系统上使用 Java 在默认浏览器中打开这些参数

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.

对于像“ http://www.google.com”这样的短网址,这很好用。但是对于长 URL(比如 2000 个字符),这根本没有任何作用:没有例外或任何类似的东西,它被简单地忽略了。

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?

a) Runtime.exec 命令或 b) rundll32 url.dll 命令是否有字符限制?如果是这样,限制是多少?

采纳答案by David Harrison

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

您将遇到这个(存档的)操作系统/浏览器特定的最大 URL 长度问题:

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

对于“rundll32 url.dll”(即 Microsoft IE),您将被限制为 2,083 个字符(包括 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)...

  1. 构建(或使用)一个 TinyURL 风格的服务,将你的长 url 变成短的、重定向的。然而,即使在这里你也会遇到同样的 URL 长度问题,只是在浏览器本身而不是你的 Runtime() 语句中。例如,浏览器窗口将打开,转到短网址,这将执行重定向到长网址并失败。

  2. 使用 POST 请求并将您的部分或全部 URL 参数隐藏在其中。您可以在 HTTP POST 请求的正文中提供非常长的参数,而不是使用 GET 调用。这不会像您的示例代码那样简单。事实上,这对于 rundll32 url.dll 组合可能非常棘手(或不可能)(我不熟悉它)......

回答by jamesh

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.

顺便说一句,我建议使用跨平台Desktop.open()Desktop.browse()仅使用Windows rundll32。如果它无法打开写入应用程序,这会给你一个 IOException。

回答by John Gardner

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

它还取决于Windows的版本,因为您可能MAX_PATH在命令行上超出了操作系统的长度?

回答by James Van Huis

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.exec(String []) 版本,您可能会更幸运。只需将所有空格分隔的参数作为单独的字符串传入:

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

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