1. 程式人生 > >GET傳參最大長度的理解誤區

GET傳參最大長度的理解誤區

零、總結

文章資料來源於網路,可能存在變動,但是原理是一樣的。

  1. HTTP 協議 未規定 GET 和POST的長度限制
  2. GET的最大長度顯示是因為 瀏覽器和 web伺服器限制了 URI的長度
  3. 不同的瀏覽器和WEB伺服器,限制的最大長度不一樣
  4. 要支援IE,則最大長度為2083byte,若只支援Chrome,則最大長度 8182byte

一、誤解

大家都知道http 中 存在 GET 和 POST 這兩種最常用的請求方式。(PUT,DELETE不在本文討論範圍之內)

誤解:HTTP 協議下的 Get 請求引數長度是有大小限制的,最大不能超過XX,而 Post 是無限制的。

1、首先即使有長度限制,也是限制的是整個 URI 長度

而不僅僅是你的引數值資料長度

2、HTTP 協議從未規定 GET/POST 的請求長度限制是多少。

The HTTP protocol does not place any a priori limit on the length of a URI. Servers MUST be able to handle the URI of any resource they serve, and SHOULD be able to handle URIs of unbounded length if they provide GET-based forms that could generate such URIs. A server SHOULD return 414 (Request-URI Too Long) status if a URI is longer than the server can handle (see section 10.4.15).
Note: Servers ought to be cautious about depending on URI lengths above 255 bytes, because some older client or proxy implementations might not properly support these lengths.

3、所謂的請求長度限制是由瀏覽器web 伺服器決定和設定的,各種瀏覽器和 web 伺服器的設定
均不一樣,這依賴於各個瀏覽器廠家的規定或者可以根據 web 伺服器的處理能力來設定。

The limit is in MSIE and Safari about 2KB, in Opera about 4KB and in Firefox about 8KB, (255 bytes if we count very old browsers) . We may thus assume that 8KB is the maximum possible length and that 2KB is a more affordable length to rely on at the server side and that 255 bytes is the safest length to assume that the entire URL will come in.
If the limit is exceeded in either the browser or the server, most will just truncate the characters outside the limit without any warning. Some servers however may send a HTTP 414 error. If you need to send large data, then better use POST instead of GET. Its limit is much higher, but more dependent on the server used than the client. Usually up to around 2GB is allowed by the average webserver. This is also configureable somewhere in the server settings. The average server will display a server-specific error/exception when the POST limit is exceeded, usually as HTTP 500 error.

IE 和 Safari 瀏覽器 限制 2k
Opera 限制4k
Firefox 限制 8k(非常老的版本 256byte)

如果超出了最大長度,大部分的伺服器直接截斷,也有一些伺服器會報414錯誤。

HTTP 1.1 defines Status Code 414 Request-URI Too Long for the cases where a server-defined limit is reached. You can see further details on RFC 2616. For the case of client-defined limits, there is no sense on the server returning something, because the server won't receive the request at all.

詳細可以看 RFC2616

The server is refusing to service the request because the Request-URI is longer than the server is willing to interpret. This rare condition is only likely to occur when a client has improperly converted a POST request to a GET request with long query information, when the client has descended into a URI "black hole" of redirection (e.g., a redirected URI prefix that points to a suffix of itself), or when the server is under attack by a client attempting to exploit security holes present in some servers using fixed-length buffers for reading or manipulating the Request-URI.

二、各個瀏覽器和web伺服器的最大長度總結

** 以下內容摘自《GET請求中URL的最大長度限制總結》, 文章內容是 2016年9月,相對比較符合當前的最新現狀。 **

在網上查詢之後,瀏覽器和伺服器對url長度都有限制,現總結如下。

瀏覽器

1、IE

IE瀏覽器(Microsoft Internet Explorer) 對url長度限制是2083(2K+53),超過這個限制,則自動截斷(若是form提交則提交按鈕不起作用)。

2、firefox

firefox(火狐瀏覽器)的url長度限制為 65 536字元,但實際上有效的URL最大長度不少於100,000個字元。

3、chrome

chrome(谷歌)的url長度限制超過8182個字元返回本文開頭時列出的錯誤。

4、Safari

Safari的url長度限制至少為 80 000 字元。

5、Opera

Opera 瀏覽器的url長度限制為190 000 字元。Opera 9 位址列中輸入190 000字元時依然能正常編輯。

伺服器

1、Apache

Apache能接受url長度限制為8 192 字元

2、IIS

Microsoft Internet Information Server(IIS)能接受url長度限制為16 384個字元。
這個是可以通過修改的(IIS7)
configuration/system.webServer/security/requestFiltering/[email protected]<requestLimits maxQueryString="length"/>

3、Perl HTTP::Daemon

Perl HTTP::Daemon 至少可以接受url長度限制為8000字元。Perl HTTP::Daemon中限制HTTP request headers的總長度不超過16 384位元組(不包括post,file uploads等)。但當url超過8000字元時會返回413錯誤。
這個限制可以被修改,在Daemon.pm查詢16×1024並更改成更大的值。

4、ngnix

可以通過修改配置來改變url請求串的url長度限制。

client_header_buffer_size 預設值:client_header_buffer_size 1k

large_client_header_buffers預設值 :large_client_header_buffers 4 4k/8k

由於jsonp跨域請求只能通過get請求,url長度根據瀏覽器及伺服器的不同而有不同限制。
若要支援IE的話,url長度限制為2083字元,若是中文字元的話只有2083/9=231個字元。
若是Chrome瀏覽器支援的最大中文字元只有8182/9=909個。

三、參考文章

相關推薦

GET長度理解誤區

零、總結文章資料來源於網路,可能存在變動,但是原理是一樣的。HTTP 協議 未規定 GET 和POST的長度限制GET的最大長度顯示是因為 瀏覽器和 web伺服器限制了 URI的長度不同的瀏覽器和WEB伺服器,限制的最大長度不一樣要支援IE,則最大長度為2083byte,若只支援Chrome,則最大長度 81

【HTTP】GET長度理解誤區

GET傳參最大長度的理解誤區 零、總結 文章資料來源於網路,可能存在變動,但是原理是一樣的。 HTTP 協議 未規定 GET 和POST的長度限制 GET的最大長度顯示是因為 瀏覽器和 web伺服器限制了 URI的長度 不同的瀏覽器和WEB伺服器,限制的最大長度不一樣 要支援IE,則最大長度為2083b

Get請求,引數的長度是多少?

HTTP Get請求URL最大長度:       瀏覽器和伺服器對url長度都有限制,各瀏覽器HTTP Get請求URL最大長度並不相同,幾類常用瀏覽器最大長度及超過最大長度後提交情況如下:  

tcp,udp報文長度

操作 miss 單元 格式 如果 mission mis src size   tcp,udp報文最大長度是怎麽樣的呢? 先來看看各個報文格式: ip報文 tcp報文 udp報文 ip和udp都有16位的長度字段,所以ip和udp報文的最大負載長度應該為2^16,64

Apache ab測試工具使用方法(無get、post)(轉)

結果 文字 測試結果 方法 htm .html 但我 apache2.4 請求 轉自Apache ab測試工具使用方法(無參、get傳參、post傳參) Ab測試工具是apache自帶的測試工具,具有簡單易上手的特性,下面我總結一下我的使用方法,首先去官方下載apache程

MySQL TEXT數據類型的長度

www hang 內容 就會 最大 imu have chang 類型 TINYTEXT 256 bytes TEXT 65,535 bytes ~64kb MEDIUMTEXT 16,777,215 bytes ~16MB

input長度限制問題

限制 input tex pre length spa 鍵盤 max logs <input type="text" maxlength="5" /> //可以 <input type="number" maxlength="5" />

求兩個字符串的公共子串的長度

max clu name ++ algorithm 字符串 har ret namespace 1 #include <iostream> 2 #include <string.h> 3 #include <algorithm>

處理特殊格式的GET

我想 spa tps cnblogs 格式 讓我 val img 亮點 有群友問 這樣的傳參格式如何接受獲取 xx.php?con="one"=>5,"two"=>0,"three"=>1 那麽我們看到使用$_GET[‘con‘]得到的是字符串 "one"

646. Maximum Length of Pair Chain 對鏈長度

fin eve select solution www elf stc amp ati You are given n pairs of numbers. In every pair, the first number is always smaller than the

11572 - Unique Snowflakes(貪心,兩指針滑動保存子段長度

fort ould inf inpu 問題 ica 兩指針 rst std Emily the entrepreneur has a cool business idea: packaging and selling snow?akes. She has devised

代碼行長度宜控制在 70 至 80 個字符以內

get 指針 out dat文件 con long could not 文件頭 std 代碼行最大長度宜控制在 70 至 80 個字符以內。代碼行不要過長,否 則眼睛看不過來,也不便於打印。 1 #include <iostream> 2 #inclu

HTTP中post和get的區別

 插一下別的知識:HTTP的請求方式 HTTP一共有8中請求方式:1.OPTIONS    2.HEAD    3.GET    4.POST    5.PUT    6.DELETE  

mysql字符集選擇和所能儲存的漢字的長度

一般我們的字符集是選擇utf-8. 4.0版本以下,varchar(20),指的是20位元組,如果存放UTF8漢字時,只能存6個(每個漢字3位元組) 5.0版本以上,varchar(20),指的是20字元,無論存放的是數字、字母還是UTF8漢字(每個漢字3位元組),都可以存放20個,最大

MySQL的text型別的長度

有個欄位是text型別,竟然67kb的內容都儲存不了,說是 Data too long  查看了一下,原來是這樣的:  TINYTEXT 256 bytes   TEXT 65,53

web中的post、get

  CTF比賽中web題型裡經常會見到post和get傳參的題型,原理也很簡單,在get傳參的時候,要構造URL拿一道BugKu中的題來舉個例子 很明顯,只需要構造what=get,回車,即可得到答案

字串長度限制ORA 01489

                字串最大長度限制ORA-014894月 8, 2008 – 1:30 下午我們知道varchar2的最大長度是4000,當處理一些大長度的欄位時4000有的時候也是不夠的。這個4000是單個欄位的長度,那麼在儲存的時候按照4000來儲存,在操作的時候在把字串合併到一起不就可以得

程式設計師面試100題之一 對稱字串的長度

                題目:輸入一個字串,輸出該字串中對稱的子字串的最大長度。比如輸入字串“google”,由於該字串裡最長的對稱子字串是“goog”,因此輸出4。分析:可能很多人都寫過判斷一個字串是不是對稱的函式,這個題目可以看成是該函式的加強版。要判斷一個字串是不是對稱的,不是一件很難的事情。我

[LeetCode] Maximum Length of Pair Chain 鏈對的長度

You are given n pairs of numbers. In every pair, the first number is always smaller than the second number. Now, we define a pair (c, d) can follow anot

Mysql 解決 phpMyAdmin 上檔案 限制

大檔案匯入mysql一直以來都是個問題,如果你懂程式的,可以直接把sql放到伺服器上,執行下source 命令匯入即可,這個部分後面我們會講,如果你使用的是phpmyadmin 那麼你可以像下面這樣做, 解決方案 開啟phpmyadmin下的配置