濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > 獲取軟件下載的真實(shí)地址!再談獲取Response.redirect重定向的URL

獲取軟件下載的真實(shí)地址!再談獲取Response.redirect重定向的URL

熱門(mén)標(biāo)簽:縣域地圖標(biāo)注打印店 鳳臺(tái)百度地圖標(biāo)注店 個(gè)人可以辦理400電話么 怎么在地圖標(biāo)注自己 修改地圖標(biāo)注 萊西電子地圖標(biāo)注 金昌電話機(jī)器人價(jià)格 外呼系統(tǒng)API接口 武夷山旅游地圖標(biāo)注

http://www.im286.com/viewthread.php?tid=1550010extra=page%3D1

其實(shí)這個(gè)問(wèn)題落伍談了n次了
其中care4也說(shuō)了兩次所以如果你有問(wèn)題最好先搜索一下 說(shuō)不定問(wèn)題早有人解決了
http://www.im286.com/viewthread. ... ;highlight=%2Bcare4
http://www.im286.com/viewthread. ... ;highlight=%2Bcare4
care4的代碼有一個(gè)小缺點(diǎn) 就是需要組件。
第一個(gè)是.net組件 二不是 但用組件始終不太方便有沒(méi)有asp直接獲取的方式呢

答案是有的
我寫(xiě)的一個(gè)vb簡(jiǎn)單的winsock獲取的代碼
http://www.im286.com/viewthread. ... t=Response.redirect


當(dāng)時(shí)我說(shuō)用asp好像不能獲得,那是當(dāng)時(shí)沒(méi)有去csdn混去,現(xiàn)在搞定了

首先我們要了解為什么xmlhttp組件無(wú)法獲得這樣的跳轉(zhuǎn)真實(shí)地址
用Response.Redirect跳轉(zhuǎn),PHP里面是Header("Location",$URL);
這兩種方式都是一樣的原理,就是在輸出的HTTP頭里面加上一個(gè)Location字段
同時(shí)把返回的HTTP狀態(tài)值設(shè)為302,瀏覽器就會(huì)認(rèn)為當(dāng)前請(qǐng)求的頁(yè)面已經(jīng)
被移動(dòng)到Location指定的路徑
那么為什么xmlhttp無(wú)法獲得呢?
原因很簡(jiǎn)單
XMLHTTP組件在處理包含Location頭的302消息時(shí)太智能了,直接給跳轉(zhuǎn)到最后的頁(yè)面,也就是說(shuō)~我們看不到中間的過(guò)程!比爾自作聰明阿 !

不過(guò)還好MSXML4里面提供了一個(gè)可用的新的組件:WinHttp.WinHttpRequest.5.1,這個(gè)也是MSXML4 XMLHTTP組件的核心。 WinHttp.WinHttpRequest有一個(gè)十分關(guān)鍵的屬性:Option,這個(gè)屬性的第六個(gè)索引就是指示是否自動(dòng)跳轉(zhuǎn),然后就可以輕松的使用XMLHTTP組件的getResponseHeader和getAllResponseHeaders方法來(lái)獲取返回的HTTP頭信息了。

好接下來(lái)就看代碼了
Dim oHttp
Set oHttp=Server.CreateObject("WinHttp.WinHttpRequest.5.1"
oHttp.Option(6)=0        '禁止自動(dòng)Redirect,最關(guān)鍵的  剩下的就簡(jiǎn)單讀取數(shù)據(jù)都估計(jì)大家都會(huì)
oHttp.SetTimeouts 5000,5000,30000,5000  '設(shè)置超時(shí)~和ServerXMLHTTP組件一樣
oHttp.Open "GET",sUrl,False       '以同步模式打開(kāi)URL
If oHttp.Status>200 And oHttp.Status>302 Then
'oHttp.Status對(duì)應(yīng)返回的HTTP狀態(tài),如果是200,表示這個(gè)就是最終頁(yè)面,沒(méi)有Location跳轉(zhuǎn)
'如果是302,表示當(dāng)前請(qǐng)求的URL已經(jīng)被移動(dòng),需要根據(jù)HTTP頭來(lái)跳轉(zhuǎn)
'對(duì)于其他數(shù)值的狀態(tài),基本上我們不要處理,但是你要處理也可以比如 440或者別的狀態(tài)你自己處理就可以了!
Else
   '在這里對(duì)返回的HTTP頭和文檔內(nèi)容進(jìn)行處理
End If

好了比較完整的代碼比較長(zhǎng)
我傳了個(gè)到空間上自己看去
http://test.aymtv.com/url.asp
默認(rèn)的輸入欄里的代碼是crsky的一個(gè)下載地址你可以測(cè)試一下就知道了
點(diǎn)查看源代碼就可以看見(jiàn)這個(gè)asp文件的源代碼!

一切搞定 over 繼續(xù)去csdn混分去了

完整代碼:
復(fù)制代碼 代碼如下:

%
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">
			要檢測(cè)的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=8downd=0ID=20780down=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,"遞歸錯(cuò)誤","遞歸嵌套超過(guò)15層可能會(huì)引起程序崩潰"
				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 "正在準(zhǔn)備獲取 "  bUrl  "br />"
				iStep=iStep+1
				if bDat>"" Then Response.Write "nbsp;nbsp;>>參數(shù): "  bDat  "br />"
				Dim oHttp : Set oHttp=Server.CreateObject("WinHttp.WinHttpRequest.5.1")
				oHttp.Option(6)=0	'禁止自動(dòng)Redirect,最關(guān)鍵的
				'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"">發(fā)生錯(cuò)誤:"  Err.Description  "/font>br />"
						Err.Clear
						GetAbsoluteURL=""
						Set oHttp=Nothing
						Response.Write "/p>"
						Exit Function
					End If
				On Error Goto 0
					Response.Write "nbsp;nbsp;>>HTTP 狀態(tài):"  oHttp.Status  "br />"
					If oHttp.Status>200 And oHttp.Status>302 Then
						Response.Write "font color=""red"">HTTP錯(cuò)誤:"  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 "nbsp;nbsp;>>Content-Type:"  oHttp.getResponseHeader("Content-Type")  "br />"
						Response.Write "nbsp;nbsp;>>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 "nbsp;nbsp;>>沒(méi)有返回Location頭,繼續(xù)分析頁(yè)面br />"
						If oHttp.getResponseHeader("Content-Type")="text/html" Then	'是HTML類型才繼續(xù)處理
							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 "nbsp;nbsp;>>發(fā)現(xiàn) Refresh 地址br />"
								Dim m : Set m=r.Execute(sBody)
								Dim tRefUrl : tRefUrl=r.Replace(m(0).Value,"$1")
								If InStr(tRefUrl,"://")=0 Then	'沒(méi)有指定協(xié)議,按當(dāng)前URL的位置重新設(shè)置
									Dim ind1 : ind1=InstrRev(sUrl,"/")
									sUrl=Left(sUrl,ind1)
									tRefUrl=sUrl  tRefUrl
								End If
								Set r=Nothing
								Set oHttp=Nothing
								Response.Write "nbsp;nbsp;>>準(zhǔn)備分析 u>"  tRefUrl  "/u>br />"
								Response.Write "/p>"
								GetAbsoluteURL=GetAbsoluteURL(tRefUrl,iStep)
								Exit Function
							Else
								Response.Write "nbsp;nbsp;>>沒(méi)發(fā)現(xiàn) Refresh Meta 轉(zhuǎn)向,這可能就是最終的URLbr />"
								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
						'這里要繼續(xù)分析網(wǎng)頁(yè)內(nèi)容
					Else
						Response.Write "nbsp;nbsp;>>Content-Type:"  oHttp.getResponseHeader("Content-Type")  "br />"
						Response.Write "nbsp;nbsp;>>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 "nbsp;nbsp;>>u>Location : "  sLoca "/u>br />"
						Response.Write "/p>"
						'這里要生成新的URL
						If InStr(sLoca,"://")=0 Then
							'沒(méi)有指定協(xié)議,按當(dāng)前URL的位置重新設(shè)置
							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;"">最終結(jié)果是:"  sAbs  "/strong>"
			End If
		%>
	script src="/T/mystat.asp?siteid=1">/script>
	/body>
/html>

您可能感興趣的文章:
  • javascript asp教程第六課-- response方法
  • javascript asp教程第七課--response屬性
  • ASP .NET調(diào)用javascript中Response.Write和ClientScript.RegisterStartupScript的區(qū)別
  • JavaEE中用response向客戶端輸出中文數(shù)據(jù)亂碼問(wèn)題分析
  • JavaEE通過(guò)response實(shí)現(xiàn)請(qǐng)求重定向

標(biāo)簽:南京 涼山 邢臺(tái) 上海 楚雄 清遠(yuǎn) 赤峰 通遼

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《獲取軟件下載的真實(shí)地址!再談獲取Response.redirect重定向的URL》,本文關(guān)鍵詞  獲取,軟件下載,的,真實(shí),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《獲取軟件下載的真實(shí)地址!再談獲取Response.redirect重定向的URL》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于獲取軟件下載的真實(shí)地址!再談獲取Response.redirect重定向的URL的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    曲阜市| 汉川市| 拜城县| 济源市| 拜泉县| 武鸣县| 齐齐哈尔市| 铁力市| 达州市| 鄂托克旗| 西华县| 武夷山市| 通城县| 建始县| 沿河| 楚雄市| 九龙城区| 宁德市| 兴安县| 遵义市| 乐业县| 梅州市| 遂昌县| 泰和县| 海城市| 芮城县| 瑞丽市| 分宜县| 万荣县| 宁城县| 拉萨市| 和硕县| 七台河市| 临夏县| 西林县| 台湾省| 文水县| 昌图县| 德钦县| 肇州县| 扶余县|