【问题标题】:AngularJS post request send option request but I've considered server side headersAngularJS 发布请求发送选项请求,但我考虑过服务器端标头
【发布时间】:2017-12-04 08:26:23
【问题描述】:

这是我的 angularJs 请求:

url = root + "/products";
$http.post(url, params)
 .then(function(response) {
         console.log('Successfull...');
});

这是我在 python tornado 中的服务器端标头:

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, PUT, DELETE")

这是我的选择方法:

def options(self, *args, **kwargs):
    self.set_status(204)
    self.finish()

为什么 angularJS 只发送一个选项请求而没有发送请求?

【问题讨论】:

  • 控制台有错误吗?

标签: python angularjs httprequest


【解决方案1】:

我相信您的问题与this 问题有关

在服务器端,我的 Web 方法是在 HTTP 响应中添加“Access-Control-Allow-Origin: *”。我可以看到响应现在确实包含此标头。我的问题是:我如何“预检”请求(选项)?我正在使用 jQuery.getJSON 发出 GET 请求,但浏览器立即取消了请求,并发出臭名昭著的:

当你发起与CORS相关的http请求时,先请求发起OPTION调用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2016-02-27
    • 1970-01-01
    • 2014-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多