URL最大長度問題

來源:互聯網
上載者:User

今天在測試Email Ticket的時候發現在進行Mark as Read/Unread操作時,請求是通過GET方式進行的。URL中列出了所有參與該操作的Ticket Id。於是,我想起GET請求是有最大長度限制的。遂輸入超長一串Ticket Id進行請求,結果頁面報錯如下:

HTTP Error 404.15 - Not FoundThe request filtering module is configured to deny a request where the query string is too long.

Most likely causes:

  • Request filtering is configured on the Web server to deny the request because the query string is too long.

Things you can try:

  • Verify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting in the applicationhost.config or web.config file.

Links and More InformationThis is a security feature. Do not change this feature unless the scope of the change is fully understood. You can configure the IIS server to reject requests whose query string is greater than a specified value. If the request's query string is greater than the configured value, this error is returned. If the allowed length of the query string needs to be increased, modify the configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting.

View more information »

經過一番搜尋之後,發現IIS 7對於Query String有長度限制。預設為2048.

該問題的解決辦法可以通過修改configuration/system.webServer/security/requestFiltering/requestLimits@maxQueryString setting.

<requestLimits maxQueryString="length" />

具體可以查看微軟KB: Error message when you visit a Web site that is hosted on a server that is running IIS 7.0: "HTTP Error 404.15 – Not Found"

 

 

搜尋過程中發現,各瀏覽器與各Web Server對URL均有長度的限制如下:

在http協議中,其實並沒有對url長度作出限制,往往url的最大長度和使用者瀏覽器和Web伺服器有關,不一樣的瀏覽器,能接受的最大長度往往是不一樣的,當然,不一樣的Web伺服器能夠處理的最大長度的URL的能力也是不一樣的。
下面就是對各種瀏覽器和伺服器的最大處理能力做一些說明.

Microsoft Internet Explorer (Browser)
IE瀏覽器對URL的最大限制為2083個字元,如果超過這個數字,提交按鈕沒有任何反應。在我的測試中,這個數字得到驗證。

微軟官方也有說明:

Microsoft Internet Explorer has a maximum uniform resource locator (URL) length of 2,083 characters. Internet Explorer also has a maximum path length of 2,048 characters. This limit applies to both POST request and GET request URLs.
If you are using the GET method, you are limited to a maximum of 2,048 characters, minus the number of characters in the actual path.
However, the POST method is not limited by the size of the URL for submitting name/value pairs. These pairs are transferred in the header and not in the URL.

Firefox (Browser)

對於Firefox瀏覽器URL的長度限制為65,536個字元,但當我測試時,最大隻能處理8182個字元,這是因為url的長度除了瀏覽器限制外,還會受Web伺服器的限制,而我本機使用的是ubuntu apache伺服器,最大處理能力為8192個字元(相差10個字元,不知道是什麼原因),一旦超過這個長度,伺服器就返回如下錯誤資訊。

Safari (Browser)
URL最大長度限制為 80,000個字元。

Opera (Browser)
URL最大長度限制為190,000個字元。

Google (chrome)
url長度一旦超過8182個字元時,出現如下伺服器錯誤:

寫道

Request-URI Too Large
The requested URL's length exceeds the capacity limit for this server.
Apache/2.2.12 (Ubuntu) Server at 127.0.1.1 Port 80

Apache (Server)
能接受最大url長度為8,192個字元,但我的測試資料是8,182,10個字元,差別不在,資料具體符合。

Microsoft Internet Information Server(IIS)
能接受最大url的長度為16,384個字元。

通過上面的資料可知,為了讓所有的使用者都能正常瀏覽,我們的URL最好不要超過IE的最大長度限制(2038個字元),當然,如果URL不直接提供給使用者,而是提供給程式調用,側這時的長度就只受Web伺服器影響了。

註:可能有些朋友會想當然的認為,如果最大長度限制為2038字元,是不是參數差不多可以傳遞1000個左右的漢字。這樣認為其實是不對的,對於中文的傳遞,最終會為urlencode後的編碼形式進行傳遞,如果瀏覽器的編碼為UTF8的話,一個漢字最終編碼後的字元長度為9個字元。

Reference from : http://www.cnblogs.com/henryhappier/archive/2010/10/09/1846554.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.