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

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

问题描述

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

是否有响应错误定义服务器可以/应该在收到超过此长度的 GET 请求时返回?

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

解决方案

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

大多数网络服务器的限制为 8192 字节 (8 KB),通常可以在服务器配置中的某处进行配置.至于客户端问题,HTTP 1.1 规范甚至对此提出警告.以下是第3.2.1章的摘录:><块引用>

注意:服务器应该谨慎依赖超过 255 字节的 URI 长度,因为一些较旧的客户端或代理实现可能无法正确支持这些长度.

Internet Explorer 和 Safari 的限制约为 2 KB,Opera 约为 4 KB,Firefox 约为 8 KB.因此,我们可以假设 8 KB 是可能的最大长度,而 2 KB 是服务器端依赖的更经济实惠的长度,并且 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天全站免登陆