debug json post data

This commit is contained in:
max/sooulix 2024-11-05 11:51:54 +01:00
commit 8406e2d3f3
1 changed files with 25 additions and 0 deletions

25
server.py Normal file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env python3
import sys
import json
from pprint import pprint
from http.server import HTTPServer, BaseHTTPRequestHandler
class DebugHTTPRequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
print(self.headers)
self.send_response(200, '')
data = self.rfile.read(int(self.headers['Content-Length']))
pprint(json.loads(data))
self.flush_headers()
def __main__(args):
with HTTPServer(args, DebugHTTPRequestHandler).serve_forever() as exc:
print(exc)
if __name__ == '__main__':
params_tuple = (sys.argv[1].split(':')[0], int(sys.argv[1].split(':')[1]))
__main__(params_tuple)