How to capture HTTP request / response headers with mitmproxy?

前端 未结 3 868
孤独总比滥情好
孤独总比滥情好 2021-02-09 12:41

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
3条回答
  •  一生所求
    2021-02-09 13:38

    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:")
    

    Command line:

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

    Output:

    ==================================================
    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
    

提交回复
热议问题