可能您已经注意到了,mitmproxy生成的流以二进制格式呈现。如果您希望以人类可读的格式保存这些流,可以在运行mitmproxy时传递一个脚本来执行此操作。
save.py
from mitmproxy.net.http.http1.assemble import assemble_request, assemble_response
f = open('/tmp/test/output.txt', 'w')
def response(flow):
f.write(assemble_request(flow.request).decode('utf-8'))
现在运行mitmproxy -s save.py
,输出将以人类可读的格式写入output.txt
。
要注意响应,因为它们可能包含大量二进制数据。但如果您确实想以人类可读的格式编写响应,则可以将f.write(assemble_response(flow.response).decode('utf-8', 'replace'))
添加到脚本中。
脚本的示例输出:
❯❯ tail -f output.txt
GET / HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:77.0) Gecko/20100101 Firefox/77.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
If-Modified-Since: Thu, 17 Oct 2019 07:18:26 GMT
If-None-Match: "3147526947"
Cache-Control: max-age=0