javascript 为 xml.HTTP.Request 设置引用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27218525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set referer for xml.HTTP.Request?
提问by user198989
I am successfully sending xml.http.request by using
我通过使用成功发送 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();
However, I couldnt able to define my referer. What is the correct way to add the custom referer ?
但是,我无法定义我的推荐人。添加自定义引用的正确方法是什么?
回答by Quentin
You cannot. The XMLHttpRequest specification forbidsthe altering of the referer
header (this stops sites lying in it to bypass security checks which some sites use the referer for).
你不能。所述的XMLHttpRequest规范禁止所述的改变referer
报头(此停止躺在它的一些网站使用引荐旁路安全检查点)。
Terminate these steps if header is a case-insensitive match for one of the following headers:
- …
- Referer
- …
如果标头是以下标头之一的不区分大小写的匹配,则终止这些步骤:
- …
- 推荐人
- …