我试图在链接megaupload中获得真正的路径,但总是但这不起作用。
function getRealURL(){
var st = new String("");
var req = new XMLHttpRequest();
req.open("GET","http://www.megaupload.com/?d=6CKP1MVJ",true);
req.send(null);
req.send(null);
req.onreadystatechange = function (aEvt) {
if (req.readyState == 4) {
if(req.status == 302){
//SUCESSO
st = req.responseText;
}
}
};//funcao
element.getElementById("id").setAttribute("value", st);
}
我需要以下链接:重定向到:http://www534.megaupload.com/files/c2c36829bc392692525f5b7b3d9d81dd/Coldplay - 警告Sign.mp3
答案 0 :(得分:6)
XMLHttpRequest
会自动跟随重定向,因此您看不到302响应。您需要将nsIHttpChannel.redirectionLimit属性设置为零以防止它:
req.open("GET","http://www.megaupload.com/?d=6CKP1MVJ",true);
req.channel.QueryInterface(Components.interfaces.nsIHttpChannel).redirectionLimit = 0;
req.send(null);
并非您在此处使用的链接会重定向到任何地方,但这是一般方法。顺便说一下,您应该查看req.getResponseHeader("Location")
。