伪造COOKIE及来源地址进行远程提交抓取内容的函数

80酷酷网    80kuku.com

      '********************************************************************************
    'Function(公有)
    '名称:    远程抓取函数
    '作用:    利用XMLHTTP远程抓取数据
    '参数:    sMethod --- 发送方式
    '    sUrl ------ 目标地址
    '    iMode ----- 返回内容类型:0为二进制,1为文本,2为cookie,3为文件头信息
    '    sBase ----- 设定编码
    '    sReferer -- 设定来源
    '    sCookie --- 设定cookie
    '    sLanguage - 设定语言
    '    sData ----- 设定要发送的参数
    '    sContent -- 设定接收数据类型
    '    sAgent ---- 设定浏览器
    '    sEncoding - 设定gzip压缩
    '    sAccept --- 设定文档类型
    '********************************************************************************
    Public Function SenFe_StealData(sMethod, sUrl, iMode, sBase, sReferer, sCookie, sLanguage, sData, sContent, sAgent, sEncoding, sAccept)
        Dim oXmlHttp : Set oXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
        With oXmlHttp
            If sMethod="" Then sMethod = "GET"
            .Open sMethod, sUrl, False
            '设定页面来源
            If sReferer<>"" Then
                .SetRequestHeader "Referer", sReferer
            Else
                .SetRequestHeader "Referer", Split(sUrl, "/")(2)
            End If
            If sCookie<>"" Then    .SetRequestHeader "Cookie", sCookie        '设定Cookie
            If sLanguage<>"" Then    .SetRequestHeader "Accept-Language", sLanguage    '设定语言
            If sData<>"" Then    .SetRequestHeader "Content-Length", Len(sData)    '设定数据长度
            If sContent<>"" Then    .SetRequestHeader "Content-Type", sContent    '设定接受数据类型
            If sAgent<>"" Then    .SetRequestHeader "User-Agent", sAgent        '设定浏览器
            If sEncoding<>"" Then    .SetRequestHeader "Accept-Encoding", sEncoding    '设定gzip压缩
            If sAccept<>"" Then    .SetRequestHeader "Accept", sAccept        '文档类型
            .Send sData
            'While .ReadyState <> 4
            '    .WaitForResponse 1000
            'Wend
            If .ReadyState<>4 Or .Status<>200 Then
                SenFe_StealData = "无法取到数据!"
                Exit Function
            End If
            Select Case iMode
                Case 0 SenFe_StealData = .ResponseBody
                Case 1
                    If sBase<>"" Then
                        SenFe_StealData = BytesToBstr(.ResponseBody, sBase)
                    Else
                        SenFe_StealData = .ResponseText
                    End If
                Case 2 SenFe_StealData = .getResponseHeader("Set-Cookie")
                Case Else SenFe_StealData = .getAllResponseHeaders()
            End Select
        End With
    End Function
    '********************************************************************************
    '作用:    编码转换
    '参数:    sBody - 要转换的内容
    '    sCset - 编码
    '********************************************************************************
    Function BytesToBstr(sBody, sCset)
        With oAdos
            .Type = 1
            .Mode = 3
            .Open
            .Write sBody
            .Position = 0
            .Type = 2
            .Charset = sCset
            BytesToBstr = .ReadText
            .Close
        End With
    End Function

分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: