xmlhttprequest状态问题302 [英] Problems with xmlhttprequest status 302

查看:281
本文介绍了xmlhttprequest状态问题302的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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);




$ b我需要这个链接:重定向到: http://www534.megaupload.com/files/c2c36829bc392692525f5b7b3d9d81dd/Coldplay - Warning Sign.mp3



登上了这个: http://www.megaupload。 com /?d = 6CKP1MVJ

解决方案

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)


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);

}

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

insted of this: http://www.megaupload.com/?d=6CKP1MVJ

解决方案

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);

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆