A function to spoof cookies and source addresses for remote submission of crawling content

Source: Internet
Author: User
Tags end set cookie
'********************************************************************************
' Function (public)
' Name: Remote crawl function
' Role: Remotely fetching data using XMLHTTP
' Parameters: Smethod---send mode
' sURL------Destination Address
' Imode-----Return content Type: 0 is binary, 1 is text, 2 is cookie,3 for file header information
' Sbase-----Set Code
' Sreferer--Set the source
' SCookie---set cookies
' Slanguage-Set language
' SData-----Set the parameters to send
' Scontent--set receive data type
' Sagent----Set browser
' Sencoding-Set gzip compression
' Saccept---Set document type
'********************************************************************************
Public Function Senfe_stealdata (Smethod, sURL, Imode, Sbase, Sreferer, SCookie, Slanguage, SData, Scontent, Sagent, sencod ING, saccept)
Dim Oxmlhttp:set oxmlhttp = Server.CreateObject ("Msxml2.serverxmlhttp")
With Oxmlhttp
If smethod= "" Then Smethod = "Get"
. Open Smethod, sURL, False
' Set page source
If sreferer<> "" Then
. setRequestHeader "Referer", Sreferer
Else
. setRequestHeader "Referer", Split (sURL, "/") (2)
End If
If scookie<> "" Then. setRequestHeader "Cookie", SCookie ' Set cookie
If slanguage<> "" Then. setRequestHeader "Accept-language", slanguage ' set language
If sdata<> "" Then. setRequestHeader "Content-length", Len (sData) ' Set data length
If scontent<> "" Then. setRequestHeader "Content-type", Scontent ' Set accept data type
If sagent<> "" Then. setRequestHeader "User-agent", Sagent ' Set browser
If sencoding<> "" Then. setRequestHeader "accept-encoding", sencoding ' set gzip compression
If saccept<> "" Then. setRequestHeader "Accept", saccept ' document type
. Send SData
' While. ReadyState <> 4
'    . waitForResponse 1000
' Wend
If. Readystate<>4 Or. status<>200 Then
Senfe_stealdata = "Unable to fetch data!" "
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
'********************************************************************************
' Function: Coded conversion
' Parameters: sbody-content to convert
' Scset-code
'********************************************************************************
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.