Problems with xmlhttprequest status 302(xmlhttprequest 状态 302 的问题)
问题描述
我正在尝试获取链接 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 的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:xmlhttprequest 状态 302 的问题


基础教程推荐
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 在 contenteditable 中精确拖放 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01