問題描述
我正在嘗試獲取鏈接 megaupload 中的真實路徑,但總是這樣,但這不起作用.
I am trying to get real path in link megaupload but always but this dont work.
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);
}
我需要這個鏈接:
Redirect to: http://www534.megaupload.com/files/c2c36829bc392692525f5b7b3d9d81dd/Coldplay - Warning Sign.mp3
插入這個:
http://www.megaupload.com/?d=6CKP1MVJ
推薦答案
XMLHttpRequest
默認自動跟隨重定向,因此您看不到 302 響應.您需要將 nsIHttpChannel.redirectionLimit 屬性設置為零以防止它:
XMLHttpRequest
follows the redirect automatically by default so you don't see the 302 response. You need to set nsIHttpChannel.redirectionLimit property to zero to prevent it:
req.open("GET","http://www.megaupload.com/?d=6CKP1MVJ",true);
req.channel.QueryInterface(Components.interfaces.nsIHttpChannel).redirectionLimit = 0;
req.send(null);
并不是說您在此處使用的鏈接會重定向到任何地方,但這是一般方法.順便說一句,您應該查看 req.getResponseHeader("Location")
,而不是查看重定向的響應文本.
Not that the link you use here redirects anywhere but this is the general approach. Btw, instead of looking at the response text for redirects you should look at req.getResponseHeader("Location")
.
這篇關于xmlhttprequest 狀態 302 的問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!