我在python中找到了一个simplewebservers的number,它可以快速启动服务器并简单地响应请求。我需要的是一个服务器,它不仅打印每个请求(127.0.0.1 - - [28/Aug/2017 10:42:11] "POST / HTTP/1.1" 200 -
)的IP地址、时间戳、方法和响应代码,而且,如果是POST请求,我需要它打印出POST数据。在
因此,例如,如果我发送一个POST请求,消息正文中有{"foo":"bar"}
,我希望服务器在响应之前将127.0.0.1 - - [28/Aug/2017 10:42:11] "POST / HTTP/1.1" 200 - {"foo":"bar"}
打印到控制台。在
我不知道如何修改上面的链接选项。如果有另一个简单的选择,那也行得通。在
要打印出发送到服务器的任何JSON,请构建一个基本的catch-all endpoint并从中打印JSON。在烧瓶中,如下所示:
以下是我打给服务器的电话:
^{pr2}$以下是服务器输出:
原始答案
一个简单的装饰师应该做到:
这个装饰器的功能与应用程序路径,但将打印发送到其端点的任何JSON数据:
使用以下代码调用:
服务器输出:
相关问题 更多 >
编程相关推荐