url get与post 请求长度限制
零、总结
文章数据来源于网络,可能存在变动,但是原理是一样的。
- HTTP 协议 未规定 GET 和POST的长度限制
- GET的最大长度显示是因为 浏览器和 web服务器限制了 URI的长度
- 不同的浏览器和WEB服务器,限制的最大长度不一样
- 要支持IE,则最大长度为2083byte,若只支持Chrome,则最大长度 8182byte
一、误解
大家都知道http 中 存在 GET 和 POST 这两种最常用的请求方式。(PUT,DELETE不在本文讨论范围之内)
误解:HTTP 协议下的 Get 请求参数长度是有大小限制的,最大不能超过XX,而 Post 是无限制的。
1、首先即使有长度限制,也是限制的是整个 URI 长度,而不仅仅是你的参数值数据长度。
2、HTTP 协议从未规定 GET/POST 的请求长度限制是多少。
*以下内容摘自 《关于 HTTP GET/POST 请求参数长度最大值的一个理解误区》, 文章时间为 2013年的。可能以当前最新的浏览器有出入 *
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/requestLimits@maxQueryStringsetting.<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个。
三、参考文章
url get与post 请求长度限制的更多相关文章
- asp.net 上传文件超过了最大请求长度
今天系统遇到了一个问题,上传4m以上的文件,uploadify就会报错:超过了最大请求长度. 开始我以为是设置的大小,可是后来我看了uploadify的fileSizeLimit=1024*10,也就 ...
- asp.net上传文件超过了最大请求长度[转]
错误消息:超过了最大请求长度 错误原因:asp.net默认最大上传文件大小为4M,运行超时时间为90S. 解决方案 1. 修改web.config文件可以改变这个默认值 ...
- .Net“/”应用程序中的服务器错误 超过了最大请求长度 错误解决办法
错误如下: 错误提示: 说明: 执行当前 Web 请求期间,出现未处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.Web.HttpE ...
- img标签src=""和background-image:url();引发两次请求页面bug
img标签src=""和background-image:url();引发两次请求页面bug 具体原因是,在img 对象的src 属性是空字符串("")的时 ...
- C# Webservice 解决在运行配置文件中指定的扩展时出现异常。 ---> System.Web.HttpException: 超过了最大请求长度问
摘自: http://blog.csdn.net/gulijiang2008/article/details/4482993 请在服务器端配置 方法一: 在通过WebService处理大数据量数据时出 ...
- web请求报出 “超过了最大请求长度” 【注意:重启IIS】
摘自:http://www.cnblogs.com/loalongblogs/archive/2012/10/16/2726372.html web请求报出 “超过了最大请求长度” 错误原因:as ...
- Asp.net上传出现“超过了最大请求长度”的问题解决方法
在开发ASP.NET网站后台管理系统时,我们可能会遇到这样的问题:上传大于4M的文件时,会提示错误:错误信息如下: 1.异常详细信息:超过了最大请求长度. 2.引发异常的方法:Byte[] GetEn ...
- .net mvc 超过了最大请求长度 限制文件上传大小
在我们的项目中遇到"超过了最大请求长度"如下图所示,是因为IIS默认请求长度4M,当请求长度大于这个值的时候报错,下面是解决方案. 解决方案:修改web.config文件 1.注意 ...
- asp.net MVC 上传文件 System.Web.HttpException: 超过了最大请求长度
APS.NET MVC 上传文件出现 System.Web.HttpException: 超过了最大请求长度 这个问题 原因是 默认最大上传文件大小为4096,而我提交的文件太大了. 解决方案:修改 ...
随机推荐
- 复习及总结--.Net线程篇(4)
这里要说的就是多线程的锁的问题了 锁:作用在于实现线程间的同步问题,最典型的是售票问题 1,InterLocked 提供的都是静态方法,用来同步对多个共享变量的访问,包括以原子方式递增,递减,比较和替 ...
- Java知识点梳理——集合
1.定义:Java集合类存放于java.util包,是存放对象的容器,长度可变,只能存放对象,可以存放不同的数据类型: 2.常用集合接口: a.Collection接口:最基本的集合接口,存储不唯一, ...
- 【BZOJ2726】[SDOI2012]任务安排 斜率优化+cdq分治
[BZOJ2726][SDOI2012]任务安排 Description 机器上有N个需要处理的任务,它们构成了一个序列.这些任务被标号为1到N,因此序列的排列为1,2,3...N.这N个任务被分成若 ...
- 【BZOJ4254】Aerial Tramway 树形DP
[BZOJ4254]Aerial Tramway 题意:给你一座山上n点的坐标,让你在山里建m条缆车,要求缆车两端的高度必须相等,且中间经过的点的高度都小于缆车的高度.并且不能存在一个点位于至少k条缆 ...
- 【BZOJ4262】Sum 单调栈+线段树
[BZOJ4262]Sum Description Input 第一行一个数 t,表示询问组数. 第一行一个数 t,表示询问组数. 接下来 t 行,每行四个数 l_1, r_1, l_2, r_2. ...
- [LeetCode] Maximum Subarray Sum
Dynamic Programming There is a nice introduction to the DP algorithm in this Wikipedia article. The ...
- 购物车-删除单行商品-HTMLTableElement.deleteRow()
wta 问题发源的代码: /*删除单行商品*/ function deleteRow(rowId){ var Index=document.getElementById(rowId).rowIndex ...
- c/c++分割字符串
c++分割字符串: http://www.martinbroadhurst.com/how-to-split-a-string-in-c.html c分割字符串: http://www.martinb ...
- python [:-1] 与 [::-1]
line = "abcde"line[:-1]结果为:'abcd' line = "abcde"line[::-1]结果为:'edcba' [:-1] b = ...
- wait_event族函数浅析
2017-06-03 周末闲暇无事,聊聊内核中的wait_event*类函数的具体实现,等待事件必定涉及到某个条件,而这些函数的区别主要是等待后唤醒的方式……直奔主题,上源码 wait_event_i ...