python tornado中的CORS仅发送选项请求
首先,我读到了这个问题:python tornado中的CORS仅发送选项请求,python,cors,httprequest,tornado,Python,Cors,Httprequest,Tornado,首先,我读到了这个问题: 我所做的是: 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")
我所做的是:
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")
还有一种选择方法:
def options(self):
self.set_status(204)
self.finish()
在我的处理程序中:
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!')
我是这样要求的:
function del(){
$.rest.put(
"http://xxx.xxx.xxx.xxx:7777/amir_test",
{user: "A",pass: "b"},
function (data) {console.log(data);}
);
}
问题是,当我向这个url发出请求时,在inspector的“网络”选项卡中只有一个选项,没有put请求。我该怎么办
访问控制仅允许
标题仅适用于GET
(以及一些POST
)请求。对于其他方法,选项
请求是必需的。您必须实现链接问题的答案中所示的options()
。我已经完成了,但忘记在此处复制,问题已更新,但结果相同!现在怎么办?您的访问控制允许方法
需要包括您支持的所有方法(在本例中包括PUT和DELETE)