3

我有两个端点,一个 www 和一个 api。API 驱动backbone.js 集合,到目前为止运行顺利。一个新的 RPC 端点未能通过 Access-Control-Allow-Origin CORS 检查,但我不知道如何调试。来自网站的几个预检 OPTIONS 调用成功地返回了结果集,但是这个新的调用完全失败了。通过单击按钮手动触发失败的新 RPC。它不存在于 iframe 或任何具有奇怪安全范围的容器中。所有这些都发生在同一个网页中。

我对某些集合有 3 次调用,请求/响应如下:

要求

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, authorization, origin
Access-Control-Request-Method:GET

回应

Access-Control-Allow-Headers:X-Requested-With,Authorization,Accept,Origin,Content-Type
Access-Control-Allow-Methods:GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:2
Content-Type:text/plain
Date:Tue, 26 Feb 2013 01:53:33 GMT
Server:nginx/1.1.19
X-Frame-Options:DENY
X-Powered-By:Express

^^ 胜利!所有集合都在填充。我可以不受惩罚地在这些集合中获取/发布/放置/删除模型。

失败的呼叫:

选项(预检)

要求

Accept:*/*
Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:accept, origin, authorization, content-type
Access-Control-Request-Method:GET
Cache-Control:no-cache
Connection:keep-alive
Host:api.bip.io
Origin:https://bip.io
Pragma:no-cache
Referer:https://bip.io/dash/account
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko Chrome/24.0.1312.52 Safari/537.17

回应

Access-Control-Allow-Headers:X-Requested-With,Authorization,Accept,Origin,Content-Type
Access-Control-Allow-Methods:GET,POST,PUT,DELETE,OPTIONS
Access-Control-Allow-Origin:*
Connection:keep-alive
Content-Length:2
Content-Type:text/plain
Date:Tue, 26 Feb 2013 01:55:26 GMT
Server:nginx/1.1.19
X-Frame-Options:DENY
X-Powered-By:Express

获取请求

GET /rpc/domain/confirm/55e648b5-1098-41e8-9d76-bd020ebe6d37

Request URL:https://api.bip.io/rpc/domain/confirm/55e648b5-1098-41e8-9d76-bd020ebe6d37
Accept:application/json, text/javascript, */*; q=0.01
Authorization:Basic {XX-OBFUSCATED}
Cache-Control:no-cache
Content-Type:application/json
Origin:https://bip.io
Pragma:no-cache
Referer:https://bip.io/dash/account
User-Agent:Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17

最后一个请求的 Chrome 错误是:

XMLHttpRequest cannot load https://api.bip.io/rpc/domain/confirm/55e648b5-1098-41e8-9d76-bd020ebe6d37. 
Origin https://bip.io is not allowed by Access-Control-Allow-Origin.

所有这些调用都通过这个 jQuery v1.8.2 方法汇集:

//  request handler
    _request : function(payload, methodAPI, methodHTTP, onSuccess, onFail) {
        var self = this;
        var payload = null == payload ? payload : JSON.stringify(payload);

        var reqStruct = {
            type: methodHTTP,
            contentType: 'application/json',
            dataType: 'json',
            url: methodAPI,
            success: function(resData, status, xhr) {
                if (undefined != onSuccess) {
                    onSuccess(resData, payload);
                }
            },
            error: function(xhr, status, errText) {
                if (undefined !== onFail) {
                    onFail(xhr.status, status, errText, payload);
                }
            }
        };

        if (null !== payload) {
            reqStruct.data = payload;
        }

        $.ajax(reqStruct);
    }

怎么调试??谢谢!

4

0 回答 0