CORS / xhr.getRequestHeaders

Hi,

I try to use CORS ( http://www.w3.org/TR/2009/WD-cors-20090317/#access-control-allow-methods-header ) for an application in Safari, and when I try to read response headers from XMLHTTPRequest I get only Content-Type. None of the other completely standard headers pass, and I cannot figure out how to make this work.

Does anyone know how to fix this problem? Could this be a WebKit bug?

Edit

here i configuration is used with nGinx:

add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers Cache-Control,Pragma,Date;
add_header Access-Control-Allow-Methods GET,POST;
+3
source share
4 answers

, JS, Access-Control-Expose-Headers , .

, . Mozilla Firefox 4, Webkit . IE8 (google , , ).

(. getResponseHeader()?) XMLHttpRequest

+1

, Cache-Control, Pragma Date? , Wireshark , HTTP-, ?

0

. https://stackoverflow.com/users/713326/gijs , , nginx, . " " , (200, 204, 301, 302 304). nginx, HttpHeadersMoreModule (http://wiki.nginx.org/HttpHeadersMoreModule). , add_header more_set_headers.

:

    more_set_headers 'Access-Control-Allow-Origin: $http_origin';
    more_set_headers 'Access-Control-Allow-Credentials: false';
    more_set_headers 'Access-Control-Allow-Methods: GET, POST, OPTIONS, HEAD, PUT, PATCH, DELETE';
    more_set_headers 'Access-Control-Allow-Headers:Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Accept,Authorization;
    more_set_headers 'Access-Control-Expose-Headers: Location';
0

:

$.ajax({
            url: "http://localhost:8079/students/add/",
            type: "POST",
            crossDomain: true,
            data: JSON.stringify(somejson),
            dataType: "json",
            success: function (response) {
                var resp = JSON.parse(response)
                alert(resp.status);
            },
            error: function (xhr, status) {
                alert("error");
            }
        });

:

response = HttpResponse(json.dumps('{"status" : "success"}'))
response.__setitem__("Content-type", "application/json")
response.__setitem__("Access-Control-Allow-Origin", "*")

return response
0

Source: https://habr.com/ru/post/1785897/


All Articles