JAVA -tomcat- 请求头太大

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39720422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 21:23:54  来源:igfitidea点击:

JAVA -tomcat- Request header is too large

javahttptomcattomcat7

提问by Sarthak Srivastava

INFO: Error parsing HTTP request header
 Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: Request header is too large
    at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:512)
    at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:501)
    at org.apache.coyote.http11.InternalInputBuffer.parseRequestLine(InternalInputBuffer.java:171)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:996)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:623)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:722

How could I solve this in my spring web application?

我怎么能在我的 spring 网络应用程序中解决这个问题?

I had gone through this thread Request header is too large

我已经通过这个线程请求标头太大

采纳答案by Sarthak Srivastava

Solved! I was using HTTP GET instead of HTTP POST. Technically I have seen HttpGet will have issue if the URL length goes beyond 2000 characters. In that case, it's better to use HttpPost or split the URL. Browsers have limits ranging on the 2kb - 8kb

解决了!我使用的是 HTTP GET 而不是 HTTP POST。从技术上讲,如果 URL 长度超过 2000 个字符,我已经看到 HttpGet 会出现问题。在这种情况下,最好使用 HttpPost 或拆分 URL。浏览器的限制范围为 2kb - 8kb

Tomcat: Request header Too large

Tomcat:请求标头太大

回答by Ashwin Gupta

It's not about POST or GET but rather what is the header size limit setup for the Tomcat used by your application.

这与 POST 或 GET 无关,而是与应用程序使用的 Tomcat 的标头大小限制设置有关。

You can always control and configure that using app properties as below: server.tomcat.max-http-header-size=1024

您始终可以使用应用程序属性来控制和配置它,如下所示:server.tomcat.max-http-header-size=1024

Where 1024 is in Bytes.

其中 1024 以字节为单位。

回答by kimy82

I know it is an old post. However I think it is good to clarify some bits.

我知道这是一个旧帖子。但是我认为澄清一些细节是好的。

  • Using _server.tomcat.max-http-header-size=max_wanted_size_ parameter you will change the server to accept up to max_wanted_size, but even if you set that to 10Mb the browser will cut your request param to the browser limit size. I have tried in chrome and it seems to be around 150-200kb.
  • The java.lang.IllegalArgumentExceptionis happening in the server and it hasn't any to do with the browser. Hence, changing server.tomcat.max-http-header-size should be good enough and it is happening when using GET method but it can also happen when using POST method (In the POST case maxPostSize parameter should be changed).
  • 使用 _server.tomcat.max-http-header-size=max_wanted_size_ 参数,您将更改服务器以接受 max_wanted_size,但即使您将其设置为 10Mb,浏览器也会将您的请求参数减少到浏览器限制大小。我在 chrome 中尝试过,它似乎在 150-200kb 左右。
  • java.lang.IllegalArgumentException异常是在服务器发生的事情,现在也没有任何做与浏览器。因此,更改 server.tomcat.max-http-header-size 应该足够好,它在使用 GET 方法时发生,但在使用 POST 方法时也可能发生(在 POST 情况下,maxPostSize 参数应该更改)。

回答by Jay

here is the question, is there any limit in HTTP headers? The Answer is No. there is no limitbut web-servers are limiting their incoming request header size even in POST requests therefore we getting 413 (Request header is too large). This limitation is including request line and header fields.

这里的问题是,HTTP 标头是否有任何限制?答案是否定的。有没有限制,但网络服务器都限制了他们进入的请求头大小,即使在POST请求,因此我们得到413(请求头太大)。此限制包括请求行和标头字段。

http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize

http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize

https://tomcat.apache.org/tomcat-5.5-doc/config/http.html

https://tomcat.apache.org/tomcat-5.5-doc/config/http.html

http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers

http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers

Maximum on http header values?

http 标头值的最大值?



In my case, I had SpringBoot 1.5.8 and used HTTP POST, however I had to add:

就我而言,我有 SpringBoot 1.5.8 并使用了 HTTP POST,但是我必须添加:

server.max-http-header-size=10000000 

in application.properties.

在 application.properties 中。

回答by Dulith De Costa

The maximum size of the request and response HTTP header, specified in bytes. If not specified, this attribute is set to 4096 (4 KB).

请求和响应 HTTP 标头的最大大小,以字节为单位。如果未指定,则此属性设置为 4096 (4 KB)。

To avoid getting Error parsing HTTP request headererror you can increase the following value by doing this.

为避免Error parsing HTTP request header出错,您可以通过执行此操作来增加以下值。

Go to following location: $TOMCAT_HOME/conf/server.xml

前往以下位置: $TOMCAT_HOME/conf/server.xml

In server.xmlchange the HTTP/1.1 Connectorentry and set the maxHttpHeaderSizeto "65536" (64Kb in bytes) as shown below:

server.xml更改HTTP/1.1 Connector条目并将其设置maxHttpHeaderSize为“ 65536”(64Kb 字节),如下所示:

<Connector port="8080" maxHttpHeaderSize="65536" protocol="HTTP/1.1" ... />

Or

或者

You can use the POST method it can carry upto 2 megabytes according to Tomcat.

您可以使用 POST 方法,根据 Tomcat 最多可以携带 2 兆字节。

The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than or equal to 0. If not specified, this attribute is set to 2097152 (2 megabytes).

将由容器 FORM URL 参数解析处理的 POST 的最大大小(以字节为单位)。可以通过将此属性设置为小于或等于 0 的值来禁用该限制。如果未指定,则此属性设置为 2097152(2 兆字节)。

Hope this information would help you..

希望这些信息能帮到你。。

回答by Poovarasan Manickam

Its an old post - but anyone looking to change server.max-http-header-size in latest spring boot (version >=2.1) - Value should be provided in Datasize parsable value e.g - server.max-http-header-size=64KB

它是一篇旧帖子 - 但任何希望在最新 Spring Boot(版本 >=2.1)中更改 server.max-http-header-size 的人 - 应在 Datasize 可解析值中提供值,例如 - server.max-http-header-size= 64KB

回答by charlie arehart

I'll add a different "answer" to this problem: the problem could be too many or too large cookies, in the browser of the user visiting the site giving the error.

我将为这个问题添加一个不同的“答案”:问题可能是cookie 太多或太大,在访问站点的用户的浏览器中给出了错误。

While most have (understandably) focused on how to change Tomcat to ALLOW a larger header, I'll point out that in a case where I experienced this error, I was able to use my browser dev tools to see that somehow there was a very large number of cookies being sent to the site which generated the error. (They seemed of a sort that I felt something on the server had been mistaken in creating so many, as they had named that were near duplicates of each other, with dupe values.)

虽然大多数人(可以理解)专注于如何更改 Tomcat 以允许更大的标头,但我会指出,在我遇到此错误的情况下,我能够使用我的浏览器开发工具来查看不知何故大量 cookie 被发送到产生错误的站点。(它们似乎有点让我觉得服务器上的某些东西在创建如此多的东西时出错了,因为它们命名为彼此接近重复的值,具有重复的值。)

I cleared the cookies for this site (using the browser dev tools), and now I did not get the error. Of course, clearing cookies can cause issues like being logged out of the site, etc. In my case, that was a small price to pay for being able to use the site again.

我清除了该站点的 cookie(使用浏览器开发工具),现在我没有收到错误消息。当然,清除 cookie 可能会导致诸如退出站点等问题。在我的情况下,为能够再次使用该站点而付出的代价很小。

I leave this in case others may hit it some day, and either be the person getting the error (like I was) or a server admin whose users are reporting it, who could ask them to consider clearing the cookies for their site (there are many ways, of course, and web sites to help).

我留下这个以防其他人有一天可能会遇到它,或者是收到错误的人(就像我一样)或者是用户报告它的服务器管理员,他们可以要求他们考虑清除他们网站的 cookie(有当然,还有很多方法和网站可以提供帮助)。