JAVA -tomcat- 请求头太大

JAVA -tomcat- Request header is too large

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

如何在我的 spring 网络应用程序中解决这个问题?

我已经看过这个帖子Request header is too large

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

Tomcat: Request header Too large

这与 POST 或 GET 无关,而是您的应用程序使用的 Tomcat 的 header 大小限制设置是多少。

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

其中 1024 以字节为单位。

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

  • 使用 _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 参数应该改变)。

问题来了,HTTP headers有限制吗?答案是没有限制,但是 web-servers 正在限制他们的传入请求 header 大小,即使在 POST 请求中也是如此,因此我们得到 413(请求 header太大)。此限制包括请求行和 header 字段。

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

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

Maximum on http header values?


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

server.max-http-header-size=10000000 

在 application.properties.

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

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

转到以下位置:$TOMCAT_HOME/conf/server.xml

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

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

您可以使用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).

希望这些信息对您有所帮助..

它是旧的 post - 但任何想要改变的人 server.max-http-header-size in latest spring boot (version >=2.1) - Value should be provided in Datasize parsable value 例如 - server.max-http-header-size=64KB

我将为这个问题添加一个不同的 "answer":问题可能是 太多或太大的 cookies,在访问网站的用户的浏览器中给出错误。

虽然大多数人(可以理解)关注如何将 Tomcat 更改为允许更大的 header,但我要指出的是,在我遇到此错误的情况下,我能够使用我的浏览器开发工具查看是否有大量 cookie 以某种方式发送到生成错误的站点。 (他们似乎是我觉得服务器上的某些东西错误地创建了这么多,正如他们所命名的那样,彼此几乎重复,具有欺骗值。)

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

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

在我的例子中,我将 blob 图像显示为 url 路径 <img src="example.com/{extremely-long-base64-encoded-string}"> 而不是 <img scr="data:;base64,{extremely-long-base64-encoded-string}">

您注意到了差异,这就是导致错误的原因 INFO: Error parsing HTTP request header java.lang.IllegalArgumentException: Request header is too large

使用 Spring Boot 2.4 in application.properties:

server.max-http-header-size=10MB

我在使用 Spring 启动应用程序时遇到了同样的错误。我只是将数据发送方式更改为使用查询参数中的 Postman 表单数据,问题已解决。

我刚刚在尝试为 NetBeans IDE.

调试 Web 应用 运行 con localhost tomcat 时遇到了这个问题

在我找到任何解决方案之前,在 Firefox 中进行了尝试,但没有出现问题。

原来 Chrome 发送了一些 cookie 值或值并达到了一些配置的限制。

刚刚从 Chrome 的开发人员工具中删除了本地主机的 cookie,问题已解决。

在我的例子中,我有一个 spring 引导应用程序,用于根据请求 URL 重定向到另一个码头应用程序。我不得不在两个地方修改它。

Spring 开机

server.max-http-header-size=20000

码头

设置 属性 requestHeaderSize 的值,如下所示。

   <Call name="addConnector">
      <Arg>
          <New class="org.eclipse.jetty.server.nio.SelectChannelConnector">
            <Set name="host"><Property name="jetty.host" /></Set>
            <Set name="port"><Property name="jetty.port" default="8080"/></Set>
            <Set name="maxIdleTime">300000</Set>
            <Set name="requestHeaderSize">20000</Set>
            <Set name="Acceptors">2</Set>
            <Set name="statsOn">false</Set>
            <Set name="confidentialPort">8443</Set>
            <Set name="lowResourcesConnections">20000</Set>
            <Set name="lowResourcesMaxIdleTime">5000</Set>
          </New>
      </Arg>
    </Call>