HTTP GET请求的最大长度 [英] Maximum length of HTTP GET request

查看:981
本文介绍了HTTP GET请求的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP GET 请求的最大长度是多少?

是否定义了一个响应错误,如果服务器收到超过此长度的GET请求,服务器可以/应该返回该错误?

这是在Web服务API的上下文中,尽管也很有趣,也可以看到浏览器的限制.

解决方案

该限制取决于所使用的服务器和客户端(如果适用,还取决于服务器或客户端所使用的代理).

大多数Web服务器的限制为8192字节(8 KB),通常可以在服务器配置中的某个位置进行配置.至于客户端问题,HTTP 1.1规范甚至对此有所警告.这是第3.2.1章的摘录:

注意:服务器应谨慎使用255个字节以上的URI长度,因为某些较旧的客户端或代理实现可能无法正确支持这些长度.

Internet Explorer和Safari的限制约为2 KB,Opera的限制约为4 KB,而Firefox的限制约为8 KB.因此,我们可以假设8KB是最大可能的长度,而2KB是在服务器端依赖的更合理的长度,并且255个字节是假定整个URL都将进入的最安全的长度.

如果在浏览器或服务器中都超过了限制,大多数将只截断超出限制的字符,而不会发出任何警告. 某些服务器可能会发送 HTTP 414错误.如果您需要发送大数据,则最好使用POST而不是GET.它的限制要高得多,但与客户端相比,它对所使用的服务器的依赖性更大.一般的网络服务器通常最多允许2 GB的存储空间.也可以在服务器设置中的某个位置进行配置.超出POST限制时,普通服务器将显示特定于服务器的错误/异常,通常是HTTP 500错误.

What's the maximum length of an HTTP GET request?

Is there a response error defined that the server can/should return if it receives a GET request that exceeds this length?

This is in the context of a web service API, although it's interesting to see the browser limits as well.

解决方案

The limit is dependent on both the server and the client used (and if applicable, also the proxy the server or the client is using).

Most web servers have a limit of 8192 bytes (8 KB), which is usually configurable somewhere in the server configuration. As to the client side matter, the HTTP 1.1 specification even warns about this. Here's an extract of chapter 3.2.1:

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.

The limit in Internet Explorer and Safari is about 2 KB, in Opera about 4 KB and in Firefox about 8 KB. We may thus assume that 8 KB is the maximum possible length and that 2 KB 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 an 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 2 GB is allowed by the average web server. This is also configurable somewhere in the server settings. The average server will display a server-specific error/exception when the POST limit is exceeded, usually as an HTTP 500 error.

这篇关于HTTP GET请求的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆