网络编程
位置:首页>> 网络编程>> Asp编程>> WinHttp.WinHttpRequest--XmlHttp获取跳转页面的功能

WinHttp.WinHttpRequest--XmlHttp获取跳转页面的功能

作者:雨哲 来源:yz81.com 发布时间:2010-03-22 14:34:00 

标签:WinHttp.WinHttpRequest,xmlhttp,跳转,采集

最近在研究雨哲软件采集程序的时候,需要获取真实软件地址时遇到了需要读取跳转页面跳转后的真实地址的问题。

在网上找了很多方法,使用WinHttp.WinHttpRequest.5.1组件终于找到解决问题的方法了。

下面是详细代码:


'==================================================
'函数名:YuZheGetTrueUrl 雨哲QQ:425162221
'作  用:检测文件是否最重文件路径
'参  数:iYuZheUrl ------将要检测的路径
'==================================================
Function YuZheGetTrueUrl(iYuZheUrl)
    'On Error Resume Next
    YuZheGetTrueUrl = ""
    If IsNull(iYuZheUrl) = True Or Len(iYuZheUrl) < 18 Or iYuZheUrl = "" Then Exit Function
    Dim YuZheHttp
    Set YuZheHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1")
    YuZheHttp.Option(6)=0 '禁止自动跳转
    YuZheHttp.SetTimeouts 5000, 5000, 30000, 5000 '设置超时
    YuZheHttp.Open "GET", iYuZheUrl, False
    YuZheHttp.Send
    If YuZheHttp.Status=302 Then '查找跳转页面
        YuZheGetTrueUrl = YuZheHttp.GetResponseHeader("Location")
    'ElseIf YuZheHttp.Status=404 Then '文件不存在
    '    YuZheGetTrueUrl = ""
    Else
        YuZheGetTrueUrl = iYuZheUrl
    End If
    Set YuZheHttp=Nothing
End Function

这里只是只是说说简单过程,具体使用请根据自己的需要进行修改。

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com