服务器根据客户端的有效请求发送400

时间:2020-08-06 14:04:23

标签: python http wireshark

我正在使用第三方远程代理,该代理在某些事件上发送POST请求。 POST请求可以发送到任何接受POST的服务器,因此我启动了一个快速烧瓶实例。

# main.py

from flask import Flask, request
app = Flask(__name__)

@app.route('/', methods=['POST'])
def hello():
    # Logging request data to console
  return request.get_data()

此简单服务器运行良好,并已与Postman进行了测试。现在,当事件发生并且远程代理尝试将数据发送到我的服务器时,我将进入日志下方。

* Detected change in '/Users/my/path/main.py', reloading
 * Restarting with stat
 * Debugger is active!
 * Debugger PIN: 000-000-000
192.168.1.2 - - [06/Aug/2020 12:06:39] code 400, message Bad HTTP/0.9 request type ('POST')
192.168.1.2 - - [06/Aug/2020 12:06:39] "POST HTTP/1.1" HTTPStatus.BAD_REQUEST -

这是我在wireshark中捕获的内容:

POST HTTP/1.1
Host:192.168.1.1
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Content-length: 6937
Content-type: text/xml
Connection: Keep-Alive

AgentID=ABCD
DataPoint=111
MoreDataPoint=222
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
        <title>Error response</title>
    </head>
    <body>
        <h1>Error response</h1>
        <p>Error code: 400</p>
        <p>Message: Bad HTTP/0.9 request type ('POST').</p>
        <p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p>
    </body>
</html>

我无法弄清楚为什么我的服务器拒绝了400请求。

1 个答案:

答案 0 :(得分:1)

HTTP / 0.9 –单线协议

HTTP的初始版本没有版本号;它后来被称为0.9,以区别于更高版本。 HTTP / 0.9非常简单:请求由一行组成,并以唯一可能的方法GET开头,后跟资源的路径(而不是URL,因为一旦连接到服务器,就不需要协议,服务器和端口)。

0.9没有“ POST”方法,因此它们仅发送“ GET”。