设置XMLHttpRequest的引荐来源? [英] Set referer for XMLHttpRequest?

查看:68
本文介绍了设置XMLHttpRequest的引荐来源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用以下命令成功发送了 XMLHttpRequest :

I am successfully sending a XMLHttpRequest by using:

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();

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

However, I could not able to define my referer. What is the correct way to add the custom referer?

推荐答案

您不能. XMLHttpRequest规范禁止更改 referer标头(这将阻止站点位于其中,以绕过某些站点使用引荐来源的安全检查).

You cannot. The XMLHttpRequest specification forbids the altering of the referer header (this stops sites lying in it to bypass security checks which some sites use the referer for).

如果标头与以下标头之一不区分大小写,请终止这些步骤:

Terminate these steps if header is a case-insensitive match for one of the following headers:

  • 推荐人

这篇关于设置XMLHttpRequest的引荐来源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆