天天看點

java.lang.IllegalArgumentException: Invalid character

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:428)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:684)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)           

複制

那麼可能需要通過以下兩種方式解決:

一、Tomcat的header緩沖區大小不夠,隻需要在server.xml中增加maxHttpHeaderSize字段即可:

<Connector URIEncoding="UTF-8" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol"
useBodyEncodingForURI="false"
enableLookups="false"
               connectionTimeout="20000"

               redirectPort="8443" maxHttpHeaderSize="你想要的大小"/>           

複制

如果是SpringBoot項目,則需要在application.yml檔案中,進行如下修改:           

複制

server:
  port: 項目端口
  # 下面這個參數是為解決問題而新增的
  tomcat:
    max-http-header-size: 8192           

複制

二、可能是因為請求協定不對,需要統一成https或http請求。

請求位址是https,把https改成http就可以了。

參考連結:https://blog.csdn.net/yanguo110/article/details/71210131