MITM代理,获取整个请求和响应字符串 [英] MITM Proxy, getting entire request and response string
问题描述
我正在使用mitmproxy来拦截流量.我想要的是能够以字符串形式获取整个请求和响应.我知道您有def response(context, flow)
,并且HTTPFlow对象具有请求和响应对象.我想要的只是一个类似这样的字符串
I am using mitmproxy for intercepting traffic. What I want is to be able to get the entire request and response in a string. I know that you have def response(context, flow)
and that the HTTPFlow object has the request and response objects. What I want is simply something like this in a string
GET http://www.google-analytics.com/collect?v=1& HTTP/1.1
Header 1: value
Header 2: value
request body
还有这个
HTTP/1.1 301 Moved Permanently
Header 1: value
Header 2: value
response body
现在,我一直在尝试通过请求和响应的不同部分和位来尝试此操作,但这很容易出错.有更好的方法吗?
Now I've been trying this by joing the different parts and bits of the requests and responses but that is prone to errors. Is there a better way to do this?
而且,mitm是否可以处理Gzip编码的响应主体?
Also, does mitm handle Gzip encoded response bodies?
推荐答案
如果有人碰到这个;上面的答案不适用于mitmproxy4.相反,可以使用以下方法:
If some one bumps into this; the above answer does not work for mitmproxy 4. Instead one can use this:
from mitmproxy.net.http.http1.assemble import assemble_request
def response(flow):
print(assemble_request(flow.request).decode('utf-8'))
这篇关于MITM代理,获取整个请求和响应字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!