asp获取软件下载的真实地址!再谈获取Response.redirect重定向的URL!(2)
来源:落伍者 发布时间:2010-03-10 22:03:00
asp获取软件下载的真实地址完整代码:
<%
Public Function Bytes2BSTR(v)
Dim r,i,t,n : r = ""
For i = 1 To LenB(v)
t = AscB(MidB(v,i,1))
If t < &H80 Then
r = r & Chr(t)
Else
n = AscB(MidB(v,i+1,1))
r = r & Chr(CLng(t) * &H100 + CInt(n))
i = i + 1
End If
Next
Bytes2BSTR = r
End Function
'==========================================================================================
If Request.QueryString="ViewSource" Then
Dim oFso : Set oFso=Server.CreateObject("Scripting.FileSystemObject")
Dim oFil : Set oFil=oFso.OpenTextFile(Server.MapPath("URL.Asp"))
Dim sTxt : sTxt=oFil.ReadAll()
oFil.Close : Set oFil=Nothing : Set oFso=Nothing
Response.ContentType="text/plain"
Response.Write sTxt
Response.ENd
End If
%><?xml version="1.0" encoding="gb2312" standalone="yes"?>
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:v="http://www.eglic.com/">
<head>
<title></title>
<meta name="Generator" content="EditPlus" />
<meta name="Author" content="eglic" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta name="CharSet" content="GB2312" />
<link rel="stylesheet" type="text/css" href="/styles/default.css" />
<style type="text/css">
@media all{
}
</style>
<script language="javascript" src="/scripts/default.js"></script>
<script language="javascript" src="/scripts/xml.js"></script>
<script language="javascript">//<!--
//--></script>
</head>
<body>
<form action="" method="POST">
要检测的URL:<input type="text" name="URL" size="50" value="<%
If Request.Form("URL")<>"" THen
Response.Write Trim(Request.Form("URL"))
Else
Response.Write "http://www.crsky.com/view_down.asp?downd_id=8&downd=0&ID=20780&down=yes"
End If
%>" />
<input type="submit" value="提交" />
<input type="button" value="查看源代码" onclick="JavaScript:window.open('<%=URLSelf%>?ViewSource');" />
</form>
<%
Public Function GetAbsoluteURL(sUrl,ByRef iStep)
Dim bUrl,bDat
If iStep>15 Then
Err.Raise vbObejctError,"递归错误","递归嵌套超过15层可能会引起程序崩溃"
End If
If InStr(sUrl,"://")<=0 Then sUrl="http://" & sUrl
If InStr(sUrl,"?")>0 THen
Dim tmpUrl : tmpUrl=split(sUrl,"?")
bUrl=tmpUrl(0)
bDat=tmpUrl(1)
Else
bUrl=sUrl
bDat=""
End If
Response.Write "<p style=""border:solid 1px silver;border-top:solid 2px red;padding:5px;margin:2px;"">"
Response.Write "第 " & iStep & " 步:"
Response.Write "正在准备获取 " & bUrl & "<br />"
iStep=iStep+1
if bDat<>"" Then Response.Write " >>参数: " & bDat & "<br />"
Dim oHttp : Set oHttp=Server.CreateObject("WinHttp.WinHttpRequest.5.1")
oHttp.Option(6)=0 '禁止自动Redirect,最关键的
'oHttp.Option()
oHttp.SetTimeouts 5000,5000,30000,5000
oHttp.Open "GET",sUrl,False
On Error Resume Next
oHttp.Send bDat
If Err.Number<>0 Then
Response.Write "<font color=""red"">发生错误:" & Err.Description & "</font><br />"
Err.Clear
GetAbsoluteURL=""
Set oHttp=Nothing
Response.Write "</p>"
Exit Function
End If
On Error Goto 0
Response.Write " >>HTTP 状态:" & oHttp.Status & "<br />"
If oHttp.Status<>200 And oHttp.Status<>302 Then
Response.Write "<font color=""red"">HTTP错误:" & oHttp.StatusText & "</font><br />"
Err.Clear
GetAbsoluteURL=""
Set oHttp=Nothing
Response.Write "</p>"
Exit Function
End If
Dim sLoca
On Error Resume Next
sLoca=oHttp.getResponseHeader("Location")
If Err.Number<>0 Then
Err.Clear
sLoca=""
End If
On Error Goto 0
If sLoca = "" Then
Response.Write " >>Content-Type:" & oHttp.getResponseHeader("Content-Type") & "<br />"
Response.Write " >>Content-Length:"
On Error Resume Next
Response.Write oHttp.getResponseHeader("Content-Length")
If Err.Number<>0 THen Err.Clear
On Error Goto 0
Response.Write "<br />"
Response.Write " >>没有返回Location头,继续分析页面<br />"
If oHttp.getResponseHeader("Content-Type")="text/html" Then '是HTML类型才继续处理
Dim sBody : sBody=Bytes2BStr(oHttp.responseBody)
Dim r : Set r=new Regexp
r.MultiLine=True
r.Global=True
r.IgnoreCase=True
r.Pattern="<meta.+http\-equiv\=\""refresh\"".+content=\""[^\;]+;url\=([^\""\s\>]*).*$"
If r.Test(sBody) Then
Response.Write " >>发现 Refresh 地址<br />"
Dim m : Set m=r.Execute(sBody)
Dim tRefUrl : tRefUrl=r.Replace(m(0).Value,"$1")
If InStr(tRefUrl,"://")<=0 Then '没有指定协议,按当前URL的位置重新设置
Dim ind1 : ind1=InstrRev(sUrl,"/")
sUrl=Left(sUrl,ind1)
tRefUrl=sUrl & tRefUrl
End If
Set r=Nothing
Set oHttp=Nothing
Response.Write " >>准备分析 <u>" & tRefUrl & "</u><br />"
Response.Write "</p>"
GetAbsoluteURL=GetAbsoluteURL(tRefUrl,iStep)
Exit Function
Else
Response.Write " >>没发现 Refresh Meta 转向,这可能就是最终的URL<br />"
GetAbsoluteURL=sUrl
Set r=Nothing
Set oHttp=Nothing
Response.Write "</p>"
Exit Function
End If
Else
GetAbsoluteURL=sUrl
Set oHttp=Nothing
Response.Write "</p>"
Exit Function
End If
'这里要继续分析网页内容
Else
Response.Write " >>Content-Type:" & oHttp.getResponseHeader("Content-Type") & "<br />"
Response.Write " >>Content-Length:"
On Error Resume Next
Response.Write oHttp.getResponseHeader("Content-Length")
If Err.Number<>0 THen Err.Clear
On Error Goto 0
Response.Write "<br />"
Response.Write " >><u>Location : " & sLoca& "</u><br />"
Response.Write "</p>"
'这里要生成新的URL
If InStr(sLoca,"://")<=0 Then
'没有指定协议,按当前URL的位置重新设置
Dim ind : ind=InstrRev(sUrl,"/")
sUrl=Left(sUrl,ind)
sLoca=sUrl & sLoca
End If
GetAbsoluteURL=GetAbsoluteURL(sLoca,iStep)
End If
End Function
If Request.Form("URL")<>"" THen
Dim iStep : iStep=1
Dim sAbs : sAbs=GetAbsoluteURL(Trim(Request.Form("URL")),iStep)
Response.Write "<strong style=""color:white;background-color:red;font-size:15px;padding:3px;margin:10px;"">最终结果是:" & sAbs & "</strong>"
End If
%>
<script src="/T/mystat.asp?siteid=1"></script>
</body>
</html>
猜你喜欢
- 工作中遇到一个很棘手的问题,交互设计师和视觉设计师在做出高保真原型后提交给前端开发工程师,最后得到的web产物从细节上和布局上都和高保真原型
- 所以对应的asp处理代码如下代码如下:dedearr=split(xiangguanid2,chr(13)) '分割成数组
- 首先介绍下简朝阳.现就职于阿里巴巴(中国)网络技术有限公司DBA Team运维部, 简朝阳是本次MYSQL技术征文大赛第三名得主(获奖文章:
- 在Soundbreak我们每天24小时不间断地播放实况音频和视频,所以对于MySQL的新增的复制特性,我们不能做出很令人信服的测试。通过测试
- 最后罗嗦一句,本人录入这篇文章用的机器上没有 ASP 环境,所以提供的代码未能进行测试,对这一点本人深表歉意。如果大家发现了代码中的任何问题
- EcmaScript正則表達式( 深入淺出系列之淺出 ^_^ )在线正则表达式测试:http://www.aspxhome.com/RegE
- 这段时间,关于asp的前途,关于asp的好坏的讨论贴,都有好些了。当然,大家的心都是好的,但是一些朋友说的话,真是让人郁闷。个人觉得,在现在
- 要读懂这些代码主要是要了解ASP中操作二进制数据的对象ADODB.Stream!本程序主要用的就是Adodb.Stream,如果你有这个基础
- 多版本并发控制Multiversion Concurrency Control大部分的MySQL的存储 引擎,比如InnoDB,Falcon
- 如果说哪个开源程序不需要介绍大家就认识,那一定是phpMyAdmin,一款流行的MySQL数据库的Web管理界面。MySQL是全球最流行的W
- 引言委托 和 事件在 .Net Framework中的应用非常广泛,然而,较好地理解委托和事件对很多接触C#时间不长的人来说并不容易。它们就
- 代码如下:'================================================== '函数名:
- 之前看到很多人一直都问CSS 中DIV垂直居中的问题,看来对此的需求还不少。现在就把我经验拿出来分享一下,希望大家鼓鼓掌。因为在 CSS 中
- 随着网页技术的发展,网络视觉设计与之前以程序员为主导的审美特征相比,具有了极大的改观。同时,随着美术、音乐、舞蹈人才的加入,网络开始在这一社
- 如何实现像腾讯QQ聊天窗口中文字链接提醒效果。完善了部分代码...比如,在不是连接的地方单击的时候,把那个提示关闭掉...在复制不成功的时候
- 1.因为oracle 10g暂时没有与win7兼容的版本,我们可以通过对安装软件中某些文件的修改达到安装的目地。 a)打开“\ORACLE1
- XSL(EXtensible Stylesheet Language)它是指可扩展样式表语言。 XSL之于 XML 就像 CSS 之于 HT
- 如何在ADO中客户端利用好缓存技术?具体应用见下例:global.asa< !--METADATA TYPE=&q
- 数据库查询优化的实用技巧:本文中,abigale代表查询字符串,ada代表数据表名,alice代表字段名。技巧一:问题类型:ACCESS数据
- 学习目的:掌握下拉列表框的用法,并理解AutoPostBack属性; 理解IsPoskBack及用法; 初识DataTable的