印出requests內容

1
2
3
4
5
6
7
8
9
10
11
12
import http
import requests
def patch_send():
old_send = http.client.HTTPConnection.send
def new_send(self, data):
print(f'{"-"*9} BEGIN REQUEST {"-"*9}')
print(data.decode('utf-8').strip())
print(f'{"-"*10} END REQUEST {"-"*10}')
return old_send(self, data)
http.client.HTTPConnection.send = new_send
patch_send()
requests.get("http://secariolabs.com")

https://secariolabs.com/logging-raw-http-requests-in-python/

Author

Steven

Posted on

2023-09-21

Updated on

2025-01-14

Licensed under

Comments