Created
January 28, 2018 22:30
-
-
Save TheRedMudder/82da65f3a73649759ed126cb7041e652 to your computer and use it in GitHub Desktop.
Handle HTTP Post W/O additional Modules
This file contains 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
from http.server import SimpleHTTPRequestHandler | |
from socketserver import TCPServer | |
from urllib.parse import parse_qsl | |
from threading import Thread | |
#Choose how you want to Process the post data in this function | |
def processPostData(post=["No Post Data"]):#Print all post data | |
for field in post: | |
print(field) | |
class PostHandler(SimpleHTTPRequestHandler): | |
def do_POST(self): | |
print("Gathered Post Data:") | |
postData=parse_qsl(self.rfile.read(int(self.headers['Content-Length'])).decode("utf-8"))#Read and Decode Post Data | |
Thread(target=processPostData, args=[postData]).start()#Send Post Data to Process | |
return SimpleHTTPRequestHandler.do_GET(self) #Handle as no Post Request was given | |
print("Go to http://localhost/ if PORT 80 taken change it on the line bellow") | |
TCPServer(("", 80), PostHandler).serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment