如何使用mitmproxy捕获HTTP请求/响应头? [英] How to capture HTTP request / response headers with mitmproxy?

查看:2613
本文介绍了如何使用mitmproxy捕获HTTP请求/响应头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经能够从智能手机捕获HTTP流量并使用命令使用mitmdump存储此流量

I have been able to capture the HTTP(s) traffic from a smartphone and also stored this traffic using mitmdump using the command

mitmdump -w outfile

这似乎转储 HTTP正文以及标题。我有兴趣只捕获标题,最好只作为单个csv行(或json字符串)。我该怎么做?

This seems to dump the HTTP body along with the headers as well. I am interested in capturing only the headers, prefarably as a single csv row (or json string). How can I do that?

推荐答案

另一个基于先前响应的派生片段并更新为python3:

Yet another derived snippet based on previous responses and updated to python3:

def response(flow):
    print("")
    print("="*50)
    #print("FOR: " + flow.request.url)
    print(flow.request.method + " " + flow.request.path + " " + flow.request.http_version)

    print("-"*50 + "request headers:")
    for k, v in flow.request.headers.items():
        print("%-20s: %s" % (k.upper(), v))

    print("-"*50 + "response headers:")
    for k, v in flow.response.headers.items():
        print("%-20s: %s" % (k.upper(), v))
        print("-"*50 + "request headers:")

命令行:

mitmdump -q - v -s parse_headers.py -R http:// localhost:9200 -p 30001

输出:

==================================================
GET / HTTP/1.1
--------------------------------------------------request headers:
CONTENT-TYPE        : application/json
ACCEPT              : application/json
USER-AGENT          : Jakarta Commons-HttpClient/3.1
HOST                : localhost
--------------------------------------------------response headers:
CONTENT-TYPE        : application/json; charset=UTF-8
CONTENT-LENGTH      : 327

这篇关于如何使用mitmproxy捕获HTTP请求/响应头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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