-
Notifications
You must be signed in to change notification settings - Fork 12
/
dummy-web-server.py
46 lines (33 loc) · 1.19 KB
/
dummy-web-server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/python3
import socket
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
import json
hostName = ""
hostPort = 8082
class MyServer(BaseHTTPRequestHandler):
# GET is for clients geting the predi
def do_GET(self):
self.send_response(200)
self.wfile.write(bytes("<p>You accessed path: %s</p>" % self.path, "utf-8"))
# POST is for submitting data.
def do_POST(self):
#print( "incomming http: ", self.path )
content_length = int(self.headers['Content-Length']) # <--- Gets the size of data
post_data = self.rfile.read(content_length) # <--- Gets the data itself
post_data_string = post_data.decode("utf-8");
print( "post data: |*********************|" )
#print( "post data: |** ", post_data, " **|" )
print( "post data: | ", post_data_string.split('&',1), "")
print( "post data: |*********************|" )
self.send_response(200)
#client.close()
#import pdb; pdb.set_trace()
myServer = HTTPServer((hostName, hostPort), MyServer)
print(time.asctime(), "Server Starts - %s:%s" % (hostName, hostPort))
try:
myServer.serve_forever()
except KeyboardInterrupt:
pass
myServer.server_close()
print(time.asctime(), "Server Stops - %s:%s" % (hostName, hostPort))