What causes "HTTP method names must be tokens" error?

13k Views Asked by At

I simply cannot access url for my spring web applications anymore cause it always throws this error:

2020-10-05 15:18:02.599  INFO 13060 --- [nio-8083-exec-1] o.apache.coyote.http11.Http11Processor   : Error parsing HTTP request header
 Note: further occurrences of HTTP request parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name [0x160x030x010x020x000x010x000x010xfc0x030x030x06m0xb9$0xccs0xc9D\0xecJA0x950x810xafM(0x1b0xbf0xad0x0d}y-}0x97S0xe70xe8e0xe30xee]. HTTP method names must be tokens
    at org.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:418) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:260) ~[tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) [tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) [tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589) [tomcat-embed-core-9.0.37.jar:9.0.37]
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.37.jar:9.0.37]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [na:1.8.0_261]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [na:1.8.0_261]
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.37.jar:9.0.37]
    at java.lang.Thread.run(Unknown Source) [na:1.8.0_261]

I've tried to clean the browser history and cookies (using different browsers), I've tried to access it with http instead of https, I've tried to run several different projects (which used to work in the past). I don't know what else I could try to solve this error.

What could be causing it?

Controller:

@Controller
public class ProductController {

@Autowired
private ProductService productService;

@Autowired
public ProductController(ProductService productService) {
    this.productService = productService;
}

@GetMapping("/products")
public ModelAndView products() {
    ModelAndView mv = new ModelAndView();

    List<Product> productList = (List<Product>) productService.getAllProducts();

    mv.addObject("activeTabProducts", true);
    mv.addObject("productList", productList);

    return mv;
}

}

3

There are 3 best solutions below

1
On

I don't know why, but it worked when I tried to access it from an anonymous tab

0
On

Following on from the suggestion by ALEXANDRE CHAGAS VIEIRA JUNIOR above, and how it also worked for me using Incognito/Private mode, proving it wasn't my application which was broken,...

So, it works in incognito. Fails with "invalid character found in method name http method names must be tokens" when normal window.

Tried clearing cookies. No luck.

Cause: Turns out something had ended up forcing my http://localhost/thing to automatically redirect to https://localhost.thing, and hence this error.

Chrome Fix: chrome://net-internals/#hsts scroll to bottom, and for Domain: localhost, clicked the Delete button and this cleared out the stuff forcing the redirect to use https. Edge was also affected which also then worked after this fix due to it being based on Chromium.

See also: https://superuser.com/questions/565409/how-to-stop-an-automatic-redirect-from-http-to-https-in-chrome

1
On

The interface you invoked has auth. You should add token to your cookie.