forked from azk0019/CourseProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_python.py
More file actions
31 lines (26 loc) · 955 Bytes
/
test_python.py
File metadata and controls
31 lines (26 loc) · 955 Bytes
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
from http.server import BaseHTTPRequestHandler, HTTPServer
import time
import json
hostName = "localhost"
serverPort = 8080
class MyServer(BaseHTTPRequestHandler):
def do_POST(self):
length = self.headers["Content-Length"]
body = (self.rfile.read(int(length)).decode('utf-8'))[1:-1]
body = body.replace('\"', '')
urls = body.split(",")
nums = [1.0, 0.56, 0.43, -0.78]
self.send_response(200)
self.send_header("Access-Control-Allow-Origin", "*")
self.send_header("Content-type", "text/html")
self.end_headers()
self.wfile.write(bytes(json.dumps(nums), "utf-8"))
if __name__ == "__main__":
webServer = HTTPServer((hostName, serverPort), MyServer)
print("Server started http://%s:%s" % (hostName, serverPort))
try:
webServer.serve_forever()
except KeyboardInterrupt:
pass
webServer.server_close()
print("Server stopped.")