【问题标题】:Java spring Request header is too largeJava spring 请求头太大
【发布时间】:2020-09-01 06:05:54
【问题描述】:

我有一个应用程序向微服务发送请求。在标题中有 JWT 令牌变大了,我得到了这个错误

Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 400 – Bad Request</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Message</b> Request header is too large</p><p><b>Description</b> The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).</p><p><b>Exception</b></p><pre>java.lang.IllegalArgumentException: Request header is too large

我发现你可以在 yml 配置文件中增加标头的最大允许大小

server:
  max-http-header-size: 5MB

但我仍然得到相同的结果。我正在使用 Spring 2.2.6

【问题讨论】:

    标签: java spring http tomcat


    【解决方案1】:

    尝试改变

    服务器: 最大http-header-size:5MB

    到:

    服务器: max-servlet-header-size: 5MB

    “http”用于spring boot 1.4.x和1.5.x,而2.x使用“servlet”关键字

    我遇到了同样的问题: spring.servlet.multipart.max-file-size=512KB 不得不改为 spring.http.multipart.max-file-size=512KB 但我的应用程序正在使用 spring.boot.1.5.4

    对于 yml 格式,请查看此帖子 https://stackoverflow.com/a/54302823/10315229

    【讨论】:

      【解决方案2】:

      https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/html/common-application-properties.html:

      HTTP 消息头的最大大小(以字节为单位)

      在代码中(https://github.com/spring-projects/spring-boot/pull/5641/files):

      @ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
      public class ServerProperties
      ...
          /**
           * Maximum size in bytes of the HTTP message header.
           */
          private int maxHttpHeaderSize = 0; // bytes
      

      因此,5M 的值很可能会转换为 5,而不是 5242880 字节(5 兆字节)。

      【讨论】:

        猜你喜欢
        • 2017-02-04
        • 1970-01-01
        • 1970-01-01
        • 2020-10-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-29
        • 2018-09-30
        相关资源
        最近更新 更多