from http.server import SimpleHTTPRequestHandler
import socketserver
class CORSRequestHandler(SimpleHTTPRequestHandler):
def end_headers(self):
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
self.send_header('Access-Control-Allow-Credentials', 'true')
SimpleHTTPRequestHandler.end_headers(self)
PORT = 8000
with socketserver.TCPServer(("", PORT), CORSRequestHandler) as httpd:
print("serving at port", PORT)
httpd.serve_forever()
标签:Control,跨域,SimpleHTTPServer,self,send,Access,header,Allow,允许
From: https://www.cnblogs.com/badpear/p/17286774.html