xmlhttprequest CORS不允许我访问我的api

时间:2016-01-26 19:54:37

标签: javascript ajax cors cgi

我真的有一些CORS的问题我有2个运行一个的web服务器正在托管的执行页面,另一个正在运行一些python cgi skripts。 我的实际网页所在页面上有这个标题:

常规

Request URL:http://10.208.71.10/de/svg/00000002.svg?base=undefined
Request Method:GET
Status Code:200 OK
Remote Address:10.208.71.10:80

响应标题:

HTTP/1.0 200 OK
Server: WebMI SDK/0.9.0
Date: Tue, 26 Jan 2016 21:33:18 GMT
Connection: Keep-Alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST
Content-Length: 2378608
Content-Type: image/svg+xml
Last-Modified: Tue, 26 Jan 2016 21:13:28 GMT
Content-Encoding: gzip

查询字符串参数:

base=undefined

此页面包含以下一小段代码:

var getJSON = function(url, successHandler, errorHandler) {
  var xhr = typeof XMLHttpRequest != 'undefined'
    ? new XMLHttpRequest()
    : new ActiveXObject('Microsoft.XMLHTTP');
  xhr.open('get', url, true);
  xhr.setRequestHeader('origin', "http://10.208.65.216*");
  xhr.onreadystatechange = function() {
    var status;
    var data;
    // https://xhr.spec.whatwg.org/#dom-xmlhttprequest-readystate
    if (xhr.readyState == 4) { // `DONE`
      status = xhr.status;
      if (status == 200) {
        data = JSON.parse(xhr.responseText);
        successHandler && successHandler(data);
      } else {
        errorHandler && errorHandler(status);
      }
    }
  };
  xhr.send();
};

当我调用getJSON(“http://10.208.65.216:8082/cgi/3daxis.py”,function(d){...},function(s){...}); 浏览器拒绝CORS错误。

运行cgi脚本的第二个web服务器会这样回答(如果浏览器对它很满意:S):

常规

Request URL:http://10.208.65.216:8082/cgi/3daxis.py
Request Method:GET
Status Code:200 Script output follows
Remote Address:10.208.65.216:8082

响应标题

HTTP/1.0 200 Script output follows
Server: SimpleHTTP/0.6 Python/2.7.3
Date: Tue, 26 Jan 2016 19:35:35 GMT
Content-type: text/plain
Content-Location: 3daxis.py
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *
Cache-Control: no-cache, no-store, must-revalidate

我做错了什么?

1 个答案:

答案 0 :(得分:0)

.globl OPENSSL_cleanse .type OPENSSL_cleanse,\@abi-omnipotent .align 16 OPENSSL_cleanse: ret # loads of OPENSSL assembly .size OPENSSL_cleanse,.-OPENSSL_cleanse 的值不能为Access-Control-Allow-Methods。我建议学习CORS protocol