GET请求方式的长度是否有限制
HTTP规范RFC-2616描述,协议原文如下:
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.
HTTP协议不对URI的长度作事先的限制,服务器必须能够处理任何他们提供资源的URI,并且应该能够处理无限长度的URIs,这种无效长度的URL可能会在客户端以基于GET方式的请求时产生。如果服务器不能处理太长的URI的时候,服务器应该返回414状态码(此状态码代表Request-URI太长)。
注:服务器在依赖大于255字节的URI时应谨慎,因为一些旧的客户或代理实现可能不支持这些长度。
协议规范中并没有对GET请求的url长度做出明确的限制规定,但 浏览器 和 服务器 对url长度都有限制,各浏览器HTTP Get请求URL最大长度并不相同,无法取消限制。
http规范也没有对post请求的参数长度做限制,主要取决于服务器是否限制,可以取消限制。
因此在传递大量参数时,需要使用post方式提交。
例如,这种接口在accountId拼接过多使得url长度超出浏览器或服务器的限制,导致请求无法发送。
@GetMapping("/getByAccountId")
@ApiOperation("根据AccountId获取列表 多个ID用 ‘,’拼接")
List<RealNameAuthenDTO> getByAccountId(@RequestParam("accountId") String accountId);