http 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 的请求长度限制是多少。

**以下内容摘自 《关于 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服务器的最大长度总结

在网上查询之后,浏览器和服务器对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个。

 

 

  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Apache HTTP GET传参是指在HTTP请求过程中,用GET方法向服务器传递参数的一种方式。HTTP GET请求可以从Web服务器上请求url位置处的资源,并在请求的URL路径和查询字符串中添加参数。一般来说,使用HTTP GET方法会将数据作为参数附加到请求的URL上,通过URL传递给服务器进行处理。传参的方式可以是键值对的形式,也可以是RESTFul风格的URL参数。 在Apache中,可以使用HttpClient类进行HTTP GET传参。使用该类发送GET请求时,通常需要提供URL以及请求参数。URL指定要请求的资源的位置,而请求参数则是需要在GET请求中传递的数据。使用HttpClient类,可以通过构造UrlEncodedFormEntity实例来传递参数,并将其附加到HTTP GET请求中发送出去。 具体实现过程如下: 1. 创建HttpClient实例 2. 创建HttpGet实例并设置url,例如`HttpGet httpGet = new HttpGet(url);` 3. 创建NameValuePair列表,存储请求参数。例如: ``` List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("param1", "value1")); params.add(new BasicNameValuePair("param2", "value2")); ``` 4. 创建UrlEncodedFormEntity实例并将参数列表附加到entity中。例如: ``` UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, "UTF-8"); httpGet.setEntity(entity); ``` 5. 发送请求并获取服务器响应结果,例如: ``` CloseableHttpResponse response = httpClient.execute(httpGet); HttpEntity responseEntity = response.getEntity(); String result = EntityUtils.toString(responseEntity); ``` 以上就是Apache HTTP GET传参的基本流程。通过此方法可以轻松向服务器传递参数,实现数据的传递和交互。同时需要注意,GET请求参数传递是通过URL进行的,因此参数的个数和传递的数据量均需要注意,以免出现数据传输的异常情况。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值