options request code example
Example 1: options http method
The OPTIONS Method lists down all the
operations of a web service supports.
It creates read-only requests to the server.
Example 2: options method
The OPTIONS Method lists down all
the operations of a web service supports.
It creates read-only requests to the server.
Example 3: how to respond to options request
class MyHandler(BaseHTTPRequestHandler):
def do_OPTIONS(self):
self.send_response(200, "ok")
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
self.send_header("Access-Control-Allow-Headers", "X-Requested-With")
def do_GET(self):
self.send_response(200)
self.send_header('Access-Control-Allow-Origin', '*')
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write("<html><body>Hello world!</body></html>")
self.connection.shutdown(1)