Firefox说“缺少“ Access-Control-Allow-Origin” CORS”,但没有

时间:2019-10-10 15:37:04

标签: python ajax python-3.x cors

我有一个ajax调用来请求python http服务器。 Firefox说“缺少Access-Control-Allow-Origin” CORS标头”,但这是一个谎言。 Firefox显示原始标头本身。

Pyton代码为:

class DepmanHTTPRequestHandler(BaseHTTPRequestHandler):

  def do_GET(self):
    ...
    self.send_header('Access-Control-Allow-Origin', '*')
    self.send_header('Access-Control-Allow-Credentials', 'true')
    self.send_header('Vary', 'Origin')
    self.send_header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE, OPTIONS')
    self.send_header("Access-Control-Allow-Headers", "Content-Type")
    ...
    self.send_response(200)
    self.end_headers()

jquery ajax调用是:

...
$.ajax({
        url: url,            // url variable builted before
        type: 'get',
        dataType: "text/plain",
        cache: false,
        processData: false,
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            //var result = data.d.results;
            //var i = result.length;
            $("#result_area").html("Unbeliveble. It's done:<br/>" + data)
        },
        error: function (err) {
            $("#result_area").html("Error:<br/>" + JSON.stringify(err));
        },
        complete: function(data) {
            $("#result_area").html() + "<br/>Call finaly completed"

        }

Firefox发送请求,并自豪地说“缺少Access-Control-Allow-Origin” CORS标头。但这仍然是一个谎言。 Firefox开发工具显示了响应头本身:

Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Vary: Origin
Access-Control-Allow-Methods: GET,PUT,POST,DELETE, OPTIONS
Access-Control-Allow-Headers: Content-Type
HTTP/1.0 200 OK
Server: BaseHTTP/0.6 Python/3.7.4
Date: Thu, 10 Oct 2019 14:49:13 GMT

那怎么可能?!?

0 个答案:

没有答案