Xmlhttprequest 302 health issues

I am trying to get the real path in the megaupload links, but always, but this does not 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); } 

I need this link:

 Redirect to: http://www534.megaupload.com/files/c2c36829bc392692525f5b7b3d9d81dd/Coldplay - Warning Sign.mp3 

installed this:

 http://www.megaupload.com/?d=6CKP1MVJ 
+3
source share
1 answer

XMLHttpRequest is automatically redirected by default, so you do not see the answer 302. You need to set the 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); 

Not that the link you use here redirects anywhere, but it is a general approach. Btw, instead of looking at the text of the redirect response, you should look at req.getResponseHeader("Location") .

+6
source

Source: https://habr.com/ru/post/1447536/


All Articles