为xml.HTTP.Request设置referer?

use*_*989 4 javascript ajax jquery internet-explorer

我正在使用成功发送xml.http.request

var createCORSRequest = function(method, url) {
  var xhr = new XMLHttpRequest();
  if ("withCredentials" in xhr) {
    // Most browsers.
    xhr.open(method, url, true);
  } else if (typeof XDomainRequest != "undefined") {
    // IE8 & IE9
    xhr = new XDomainRequest();
    xhr.open(method, url);
  } else {
    // CORS not supported.
    xhr = null;
  }
  return xhr;
};

var url = 'http://www.whatismyip.com';
var method = 'GET';
var xhr = createCORSRequest(method, url);

xhr.onload = function() {
  // Success code goes here.
};

xhr.onerror = function() {
  // Error code goes here.
};


xhr.setRequestHeader('referer', 'http://www.google.com');
xhr.send();
Run Code Online (Sandbox Code Playgroud)

但是,我无法定义我的引用者.添加自定义引用的正确方法是什么?

Que*_*tin 11

你不能.所述的XMLHttpRequest规范禁止所述的改变referer报头(此停止站点躺在它绕过其中的一些网站使用引荐安全检查).

如果header是以下标头之一的不区分大小写的匹配项,请终止这些步骤:

  • ...
  • 引荐
  • ...