通过修改referer下载文件的方法

时间:2021-05-25

GetFile.wsc
复制代码 代码如下:
<?xmlversion="1.0"encoding="gb2312"?>
<component>
<?componenterror="true"debug="true"?>
<public>
<propertyname="Referer"/>
<propertyname="Content"/>
<propertyname="Data"/>
<methodname="GetFile">
<parametername="URL"/>
</method>
<methodname="Save">
<parametername="Path"/>
</method>
</public>
<implementstype="Behavior">
<eventname="ondowncomplete"/>
</implements>
<objectprogid="Microsoft.XmlHttp"id="Http"/>
<scriptlanguage="javascript">
<![CDATA[
varReferer,Content,Data;
varStream=newActiveXObject("ADODB.Stream");
Stream.Type=1;
functiononReady()
{
if(Http.readyState==4)
{
Content=Http.responseText;
Data=Http.responseBody;
fireEvent("ondowncomplete");
Http.abort();
}
}
functionGetFile(URL)
{
Http.onreadystatechange=onReady;
Http.open("GET",URL,true,"","");
if(Referer)Http.setRequestHeader("Referer",Referer);
Http.send(null);
}
functionSave(Path)
{
Stream.Open();
Stream.Write(Data);
Stream.SaveToFile(Path,2);
Stream.Close();
}
]]>
</script>
</component>

test.hta
复制代码 代码如下:
<html><head><script>
varDown=document.createElement("Comment");
document.lastChild.lastChild.appendChild(Down);
Down.style.behavior="url(GetFile.wsc)";
Down.ondowncomplete=function()
{
//document.write(Down.Content);
Down.Save(SaveTo.value);
Go.disabled=0;
alert("OK");
}
functionGetFile()
{
Go.disabled=1;
Down.Referer=Referer.value;
Down.GetFile(URL.value);
}
</script>
</head><body>
URL:<inputid="URL"size="50"value="http://www.booksky.biz/SendFile.aspx?FileID=15531"><br>
Referer:<inputname="Referer"size="40"value="http://www.booksky.biz"><br>
SaveTo:<inputname="SaveTo"size="40"value="D:\Test.gif"><br>
<inputid="Go"type=buttonvalue="下载"onclick="GetFile()">
</body></html>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章