如何在javascript中发送全新的请求
我目前正在写一个用户脚本。这意味着,javascript被“注入”到一个网站中,用户脚本在访问时由浏览器指定 现在我只想得到最后的500字节,例如这个网站 使用Greasemonkey,一切正常:如何在javascript中发送全新的请求,javascript,http-headers,xmlhttprequest,Javascript,Http Headers,Xmlhttprequest,我目前正在写一个用户脚本。这意味着,javascript被“注入”到一个网站中,用户脚本在访问时由浏览器指定 现在我只想得到最后的500字节,例如这个网站 使用Greasemonkey,一切正常: GM_xmlhttpRequest({ method: 'GET', headers: { "Accept-Encoding": "", "Range": "bytes=-500" }, url: window.
GM_xmlhttpRequest({
method: 'GET',
headers: {
"Accept-Encoding": "",
"Range": "bytes=-500"
},
url: window.location.href.match(/http:\/\/[\s\S]*\//) + 'res/'+threadid+".html",
onload: function(responseDetails) {
console.log(responseDetails.responseText.length);
}
});
但这样做没有像GM_xmlhttpRequest一样
var r = new XMLHttpRequest();
r.onreadystatechange=function(){if(r.readyState==4)console.log ( r.responseText.length );};
r.open('GET', 'res/'+threadid+".html",true);
r.setRequestHeader('Range', 'bytes=-500');
r.setRequestHeader('Accept-Encoding', '');
r.send(null);
或者使用jQuery或Ajax将导致
接受编码:gzip,deflate
因此,此标头已设置,无法更改
现在,正如我所知道的,我不能更改这个标题,我可以以某种方式执行一个全新的请求吗,就像Greasemonkey使用的那样?chrome和Opera的Tampermonkey在这里也失败了。。。
或者,即使是gzip编码,我也可以获取最后500个字节吗?并非所有服务器都会满足所有页面的范围请求。“你确定这一个可以吗?”我说:“我试过了。”。我使用了“实时HTTP头”,GM_xmlhttpRequest-function也在使用Range!