有没有办法克服URL长度的2k字符限制?

时间:2021-08-15 01:24:12

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?

我认为URL长度只能是2000个左右。否则,它会阻塞某些版本的IE。有没有办法克服这个问题?

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

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

Update:

I need such long URL because I need to be able for people to bookmark the URL or to send it to other people by email.

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

5 个解决方案

#1


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(我认为限制实际上是2083个字符,出于某种原因)。

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.

由于IE需要一次性发送到服务器的URL,我想不出任何能让你解决它的聪明技巧。我考虑过的一些选项是通过POST而不是GET发送查询参数(但是这在服务器端通常是不可互换的,客户端会以不同的方式对待这一点,因为URL不能出现在超链接中或被加入书签或者手动输入,如果用户想要刷新,他们将获得“再次发送信息”警告,这是有道理的,因为POST意味着更新远程服务器上的信息,并且它只有在它是推送它的查询字符串时才有效超出限制,而不是一些不道德的URL)。或者,您可以将URL分块,在cookie中设置溢出部分,然后向URL的存根发出请求,该URL足够智能,可以将上下文从cookie中拉出并将其附加到实际收到的URL。然而,这再次使服务器上的处理变得复杂,可能远远超出了普通应用程序之外的使用,并且仍然意味着您不能将该URL放在超链接或书签或其他任何内容中,因为它的一个重要部分是客户端状态。

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.

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

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

(虽然如果你可以使用tinyurl之类的东西作为代理而不是发布浏览器重定向到URL,那可能会有效)。

#2


That's what POST is for ;)

这就是POST的用途;)

#3


For bookmarking reasons you could store a hash of the argument string in the databse as well as the argument list. That way when somone bookmarks something they get a bookmark with the hash in it and your internal software looks up the appropriate arguments and gets them.

对于书签原因,您可以在数据库和参数列表中存储参数字符串的哈希值。这样当somone书签的东西时,他们会得到带有散列的书签,而你的内部软件会查找适当的参数并获取它们。

You are in essence rolling your own tiny url.

你本质上是在推动你自己的小网址。

If somone else wants to bookmark a page with the same arguments then the hash will be the same.

如果其他人想要使用相同的参数为页面添加书签,则哈希将是相同的。

the only problem is that your table of hashes will grow quite big, and many of these "book marks" might never be used.

唯一的问题是你的哈希表会变得很大,许多这些“书签”可能永远不会被使用。

#4


HTML POST is designed for transferring larger amounts of data. You should look at that.

HTML POST旨在传输大量数据。你应该看看那个。

#5


What do your urls look like? Maybe you could use gzip or md5 to shorten them, or store them in a database and put the id of the row in the url?

你的网址是什么样的?也许你可以使用gzip或md5来缩短它们,或者将它们存储在数据库中并将行的id放在url中?

#1


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(我认为限制实际上是2083个字符,出于某种原因)。

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.

由于IE需要一次性发送到服务器的URL,我想不出任何能让你解决它的聪明技巧。我考虑过的一些选项是通过POST而不是GET发送查询参数(但是这在服务器端通常是不可互换的,客户端会以不同的方式对待这一点,因为URL不能出现在超链接中或被加入书签或者手动输入,如果用户想要刷新,他们将获得“再次发送信息”警告,这是有道理的,因为POST意味着更新远程服务器上的信息,并且它只有在它是推送它的查询字符串时才有效超出限制,而不是一些不道德的URL)。或者,您可以将URL分块,在cookie中设置溢出部分,然后向URL的存根发出请求,该URL足够智能,可以将上下文从cookie中拉出并将其附加到实际收到的URL。然而,这再次使服务器上的处理变得复杂,可能远远超出了普通应用程序之外的使用,并且仍然意味着您不能将该URL放在超链接或书签或其他任何内容中,因为它的一个重要部分是客户端状态。

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.

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

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

(虽然如果你可以使用tinyurl之类的东西作为代理而不是发布浏览器重定向到URL,那可能会有效)。

#2


That's what POST is for ;)

这就是POST的用途;)

#3


For bookmarking reasons you could store a hash of the argument string in the databse as well as the argument list. That way when somone bookmarks something they get a bookmark with the hash in it and your internal software looks up the appropriate arguments and gets them.

对于书签原因,您可以在数据库和参数列表中存储参数字符串的哈希值。这样当somone书签的东西时,他们会得到带有散列的书签,而你的内部软件会查找适当的参数并获取它们。

You are in essence rolling your own tiny url.

你本质上是在推动你自己的小网址。

If somone else wants to bookmark a page with the same arguments then the hash will be the same.

如果其他人想要使用相同的参数为页面添加书签,则哈希将是相同的。

the only problem is that your table of hashes will grow quite big, and many of these "book marks" might never be used.

唯一的问题是你的哈希表会变得很大,许多这些“书签”可能永远不会被使用。

#4


HTML POST is designed for transferring larger amounts of data. You should look at that.

HTML POST旨在传输大量数据。你应该看看那个。

#5


What do your urls look like? Maybe you could use gzip or md5 to shorten them, or store them in a database and put the id of the row in the url?

你的网址是什么样的?也许你可以使用gzip或md5来缩短它们,或者将它们存储在数据库中并将行的id放在url中?