make things work

master
Ubuntu 2017-02-15 19:37:53 -05:00
parent bf9779d0e9
commit 0aa482bdca
1 changed files with 8 additions and 5 deletions

View File

@ -1,20 +1,23 @@
#!/usr/bin/python #!/usr/bin/python3
from http.server import HTTPServer, CGIHTTPRequestHandler from http.server import HTTPServer, CGIHTTPRequestHandler
import urllib import urllib
import json as jsonlib
class POSTHandler(CGIHTTPRequestHandler): class POSTHandler(CGIHTTPRequestHandler):
def do_POST(self): def do_POST(self):
length = int(self.headers['Content-Length']) length = int(self.headers['Content-Length'])
post_data = urllib.parse.parse_qs(self.rfile.read(length).decode('utf-8')) data_string = self.rfile.read(length).decode('utf-8')
print(post_data)
# You now have a dictionary of the post data
self.send_response(200) self.send_response(200)
self.end_headers() self.end_headers()
data = jsonlib.loads(data_string)
print(data['text'])
return return
if __name__ == '__main__': if __name__ == '__main__':
server = HTTPServer(('localhost', 5001), POSTHandler) server = HTTPServer(('0.0.0.0', 5001), POSTHandler)
print('Starting server...') print('Starting server...')
server.serve_forever() server.serve_forever()