Created
July 4, 2014 11:01
-
-
Save rizsotto/73c0475ed694befc3058 to your computer and use it in GitHub Desktop.
HTTP POST with standard python modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.server | |
import socketserver | |
import logging | |
import urllib.parse as p | |
PORT = 8000 | |
class ServerHandler(http.server.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
logging.error(self.headers) | |
http.server.SimpleHTTPRequestHandler.do_GET(self) | |
def do_POST(self): | |
# Extract and print the contents of the POST | |
length = int(self.headers['Content-Length']) | |
post_data = p.parse_qs(self.rfile.read(length).decode('utf-8')) | |
logging.error(post_data) | |
self.send_response(200) | |
self.send_header("Content-type", "text/html") | |
self.end_headers() | |
Handler = ServerHandler | |
httpd = socketserver.TCPServer(("", PORT), Handler) | |
print("serving at port", PORT) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment