有什么办法可以克服 URL 长度的 2k 个字符限制?

问题描述:

我认为 URL 长度只能是 2000 个左右的字符.否则,它会卡住某些版本的 IE.有什么办法可以克服这个问题吗?

I think the URL length can only be 2000 or so characters long. Otherwise, it will choke some versions of IE. Is there any way to overcome this problem?

起初我在考虑 tinyurl,但 tinyurl 实际上立即重定向到更长的 URL,所以这也可能会失败.

At first i was thinking about tinyurl, but tinyurl actually immediately redirects to the longer URL, so that probably will fail too.

我需要这么长的 URL,因为我需要能够让人们将 URL 加入书签或通过电子邮件将其发送给其他人.

没有现实的方法来解决这个问题 - 这不是规范或类似的限制,而是 IE 本身以及 URL 的分配方式(顺便说一下,我相信限制实际上是 2083 个字符.

There's no realistic way to get around this - it's not a limitation in the specs or anything like that, but in IE itself and presumably how the URL is allocated (I believe the limit is actually 2083 characters by the way, for some reason).

由于 IE 需要一次性将 URL 发送到服务器,所以我想不出任何能让您解决此问题的聪明技巧.我考虑过的一些选项是通过 POST 而不是 GET 发送查询参数(但这在服务器端通常是不可互换的,并且客户端将对此进行不同的处理,因为 URL 不能出现在超链接中或被添加书签或手动输入,如果用户想要刷新,他们会收到再次发送信息"警告,这是有道理的,因为 POST 旨在更新远程服务器上的信息,而且它只会工作如果是查询字符串超出限制而不是一些不敬虔的 URL).或者,您可以将 URL 分块,在 cookie 中设置溢出部分,然后向 URL 的存根发出请求,该存根足够智能,可以从 cookie 中提取上下文并将其附加到实际收到的 URL.然而,这再次使服务器上的处理复杂化,可能超出普通应用程序使用太多,并且仍然意味着您不能将该 URL 放在超链接或书签或其他任何内容中,因为它的一个重要部分是客户端状态.

Since IE needs the URL all in one go to send to the server, I can't think of any clever tricks that would enable you to work around it. Some options I considered were to send the query parameters via POST instead of GET (but this is often not interchangeable on the server side, and the clients will treat this differently in that the URL can't then appear in a hyperlink or be bookmarked or entered manually, and if the user wants to refresh they'll get the "send information again" warning, which makes sense since POST is meant to update information on the remote server, and it'll only work if it's the query string pushing it beyond the limit rather than some ungodly URL). Alternatively you could perhaps chunk up the URL, setting the overflow part in a cookie and then making the request to the stub of the URL, which is intelligent enough to pull the context out of the cookie and append it to the URL actually received. However this again complicates processing on the server, probably far too much to be used beyond a trivial application, and also still means you can't put that URL in hyperlinks or bookmarks or whatever, since an important part of it is client state.

基本上,其他一切都涉及重写服务器以某种方式将额外信息拼凑起来,如果您能够做到这一点,那么您应该能够简单地更改 URL 方案,使所有内容都低于 2000 个字符.所以不 - 没有真正的解决方法.

Basically, everything else would involve rewriting the server to somehow piece together the extra information, and if you're able to do this then you should be able to simply change the URL scheme so that everything's below 2000 characters. So no - no real way around it.

(不过,如果您可以使用诸如 tinyurl 之类的东西来充当代理,而不是将浏览器重定向到 URL,那还是可行的).

(Though if you could use something like tinyurl to act as a proxy rather than issuing a browser redirect to the URL, that could work).