Jul-16-2019, 03:26 PM
I have a python webserver:
Let's say I have a POST request:
localhost:8080/?paramone=alpha¶mtwo=bravo¶mthree=charlie
And I want to return the value of 'paramtwo' two the user, how do I go about doing this?
from http.server import HTTPServer, BaseHTTPRequestHandler from io import BytesIO class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): def do_GET(self): self.send_response(200) self.end_headers() self.wfile.write(b'Hello, world!') def do_POST(self): content_length = int(self.headers['Content-Length']) body = self.rfile.read(content_length) self.send_response(200) self.end_headers() response = BytesIO() response.write(b'This is a POST request \n') response.write(b'Received: ') response.write(body) self.wfile.write(response.getvalue()) httpd = HTTPServer(('localhost', 8080), SimpleHTTPRequestHandler) httpd.serve_forever()Made from various snippets of code I've pieced together from forums. I want a simple webserver that accepts GET and POST requests.
Let's say I have a POST request:
localhost:8080/?paramone=alpha¶mtwo=bravo¶mthree=charlie
And I want to return the value of 'paramtwo' two the user, how do I go about doing this?