0

First of all I've read this question: Tornado server: enable CORS requests
What I did is:

class BaseHandler(RequestHandler):
    def set_default_headers(self, *args, **kwargs):
        self.set_header("Access-Control-Allow-Origin", "*")
        self.set_header("Access-Control-Allow-Headers", "x-requested-with")
        self.set_header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")

And also an option method:

def options(self):
    self.set_status(204)
    self.finish()

And in my handler:

class AmirTest(BaseHandler):
    def get(self, *args, **kwargs):
        self.write('You have requested get method!')

    def post(self, *args, **kwargs):
        self.write('You have requested post method!')

    def put(self, *args, **kwargs):
        self.write('You have requested put method!')

    def delete(self, *args, **kwargs):
        self.write('You have requested delete method!')

This is how I request:

function del(){
    $.rest.put(
        "http://xxx.xxx.xxx.xxx:7777/amir_test",
        {user: "A",pass: "b"}, 
        function (data) {console.log(data);}
    );
}

The problem is when I made a request this url, in the network tab of inspector there is only an option and no put request. what should I do?

Loot at the inspect element

ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112

1 Answers1

1

The Access-Control-Allow headers alone only work for GET (and some POST) requests. For other methods, the OPTIONS request is mandatory. You must implement options() as shown in the answer to the linked question.

Ben Darnell
  • 21,844
  • 3
  • 29
  • 50