在Flask或WSGI中打印原始HTTP请求 [英] Print raw HTTP request in Flask or WSGI

查看:430
本文介绍了在Flask或WSGI中打印原始HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试我建立的微控制器,它正在逐行写入原始的HTTP请求。我使用Flask作为我的后端,我希望看到整个请求,因为它出现在这种格式:

  GET / HTTP /1.1 
Content-length:123
User-agent:blah
...

我知道Flask是基于WSGI的。有没有办法让这个工作与Flask?

解决方案

用瓶你有访问请求对象,其中包含所有的HTTP详细信息:

 来自瓶子导入请求

@ app.route('/')
def index():
print request.headers


I am debugging a microcontroller I've built which is writing raw HTTP requests line by line. I am using Flask for my backend and I would like to see the entire request as it appears in this format:

GET / HTTP/1.1
Content-length: 123
User-agent: blah
...

I know Flask is based on WSGI. Is there anyway to get this to work with Flask?

解决方案

With flask you have access to the request object which contains all the HTTP details:

from flask import request

@app.route('/')
def index():
    print request.headers

这篇关于在Flask或WSGI中打印原始HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆