java 在方法名称中发现无效字符。HTTP 方法必须是令牌

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44372545/
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-11-03 08:08:28  来源:igfitidea点击:

Invalid character found in method name. HTTP method must be tokens

javapythontomcatspring-bootraspberry-pi

提问by Kiith Nabaal

Edit: I no longer work at this place, and we switched to node.js anyway, so I cannot verify if anyone's answers are correct. Please vote to close (just need one more).

编辑:我不再在这个地方工作,无论如何我们切换到 node.js,所以我无法验证是否有人的答案是正确的。请投票关闭(只需要一个)。

This is not a duplicate of the other questions (or at least the ones I came across) because I don't use SSL/HTTPS anywhere in my code. I was also able to confirm that these errors are coming from my system and not an outside source (like a bot). If it is something simple then I apologize, I only started using Spring Boot a few months ago.

这不是其他问题(或者至少是我遇到的问题)的重复,因为我没有在代码中的任何地方使用 SSL/HTTPS。我还能够确认这些错误来自我的系统而不是外部来源(如机器人)。如果这很简单,那么我很抱歉,我几个月前才开始使用 Spring Boot。

I am developing an internet of things system where I send a Raspberry Pi Zero W out into the field with sensors. The Raspberry Pi gets sensor data via Bluetooth LE, and HTTP POSTS the data to a Spring Boot server (which is hosted on an AWS EC2 instance). Strangely, the server gets data perfectly fine for a while (in this case, 3 weeks), and then out of nowhere I started getting this exception from Spring/Tomcat:

我正在开发一个物联网系统,我将一个 Raspberry Pi Zero W 发送到带有传感器的现场。Raspberry Pi 通过蓝牙 LE 获取传感器数据,然后 HTTP 将数据发布到 Spring Boot 服务器(托管在 AWS EC2 实例上)。奇怪的是,服务器在一段时间内(在本例中为 3 周)获取的数据完全正常,然后我突然开始从 Spring/Tomcat 获取此异常:

2017-06-03 06:17:07.508 INFO 19927 --- [p-nio-80-exec-8]o.apache.coyote.http11.Http11Processor : Error parsing HTTP request headerNote: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

2017-06-03 06:17:07.508 INFO 19927 --- [p-nio-80-exec-8]o.apache.coyote.http11.Http11Processor : Error parsing HTTP request headerNote: further occurrences of HTTP header parsing errors will be logged at DEBUG level.

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokensatorg.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:421) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11] (rest of the stack trace)

java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokensatorg.apache.coyote.http11.Http11InputBuffer.parseRequestLine(Http11InputBuffer.java:421) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11] (rest of the stack trace)

As I mentioned above, I am not using HTTPS in either Spring Boot or the Raspberry Pi. Since the Raspberry Pi is being deployed to a remote location, I am not changing the code.

正如我上面提到的,我没有在 Spring Boot 或 Raspberry Pi 中使用 HTTPS。由于 Raspberry Pi 被部署到远程位置,因此我不会更改代码。

The program running on the Raspberry Pi is written in Python, and I use the requests.postmethod to send the data to the server.

树莓requests.post派上运行的程序是用Python编写的,我用这个方法将数据发送到服务器。

I noticed this behavior in an earlier deployment of the system as well, which used an Android device to send the data instead. So I don't think there is anything wrong with the clients...

我在系统的早期部署中也注意到了这种行为,它使用 Android 设备来发送数据。所以我不认为客户有什么问题......

I have tested the server quite a bit, especially when I add new features, and I never got this error before (except in the previous deployment). Once this error occurs, it seems like it just continues to happen (I lost 3 sensor readings in a row, all at different days/times).

我已经对服务器进行了相当多的测试,特别是当我添加新功能时,我以前从未遇到过这个错误(除了在之前的部署中)。一旦发生此错误,它似乎只会继续发生(我连续丢失 3 个传感器读数,均在不同的日期/时间)。

Is data getting corrupted as it leaves the Raspberry Pi? Does requests.posthave some odd behavior I am unaware of? Does the code I write using Spring affect Tomcat somehow? I have no idea why this is happening and all of the other answers I came across say its usually because of an HTTPS to HTTP connection. My application.properties file only has server.port=80

数据在离开 Raspberry Pi 时是否会损坏?是否requests.post有一些我不知道的奇怪行为?我使用 Spring 编写的代码是否会以某种方式影响 Tomcat?我不知道为什么会发生这种情况,我遇到的所有其他答案都说这通常是因为 HTTPS 到 HTTP 连接。我的 application.properties 文件只有 server.port=80

Thank you very much for any help!

非常感谢您的帮助!

回答by Siraj K

I had a similar issue and adding

我有一个类似的问题并添加

<dependency>
    <groupId>com.fasterxml.Hymanson.core</groupId>
    <artifactId>Hymanson-databind</artifactId>
    <version>2.6.3</version>
</dependency>

fixed the issue for me.

为我解决了这个问题。

回答by u10925557

#Increase header buffer size
#server.tomact.max-http-header-size: 8192   this is lose efficacy 
server.max-http-header-size=15360