<%
'----------get content remotely and have the content on the local computer, including any files! ----------
'---------------use XMLHTTP and ADODB.stream-----------------
' On Error Resume Next
'-------------------------------defines the output format-----------------------------
Path=request ("path")
If Path = "" Then
Path= "Http://pcqc.86516.com/index.asp"
' Here is the definition of the URL is Baidu, note must have a file suffix
End If
spath = Path
If left (LCase (path), 7) <> "http://" then
'-------------if HTTP is not in front of the local file, give LocalFile processing------------
LocalFile (PATH)
Else
'--------------------Otherwise for remote files, to RemoteFile processing------------------
RemoteFile (Path)
End If
' Response.Write Err. Description
'--------------processing function-----------
Sub LocalFile (Path)
'-------------------simply jump to the page if it is a local file-------------------
' Response.Redirect Path
Response.Write "An error has occurred! "
End Sub
Sub RemoteFile (spath)
'-------------------------processing remote file Functions------------------------------
FileName = GetFileName (spath)
'-------------GetFileName the process of converting addresses to qualified file names-------------
filename = Server.MapPath ("cache/" & filename)
Set objFSO = Server.CreateObject ("Scripting.FileSystemObject")
' Response.Write FileName
If Objfso.fileexists (FileName) Then
'--------------Check to see if the file is already visited, and if so, simply jump------------
Response.Redirect "cache/" & GetFileName (Path)
Else
'----------------Otherwise, read the GetBody function First----------------------
' Response.Write Path
t = GetBody (Path)
'-----------------is written to the browser using the binary method--------------------------
Response.BinaryWrite T
Response.Flush
'-----------------Output buffer------------------------------------------
SaveFile T,getfilename (PATH)
'------------------cache the contents of the file to the local path for the next visit-----------
End If
Set objFSO = Nothing
End Sub
Function getbody (URL)
'-----------------------function for remote fetch of content---------------------
' On Error Resume Next
' Response.Write URL
Set retrieval = CreateObject ("Microsoft.XMLHTTP")
'----------------------set up the XMLHTTP object-----------------------------
With retrieval
. Open "Get", url, False, "", ""
'------------------send-----------------------with Get, asynchronous method
. Send
' GetBody =. ResponseText
GetBody =. Responsebody
'------------------function returns the contents of the Fetch--------------------------
End With
Set retrieval = Nothing
' Response. Write Err. Description
End Function
Function GetFileName (str)
'-------------------------This function is a qualified filename function-------------------
str = Replace (LCase (str), "http://", "")
str = Replace (LCase (str), "//", "/")
str = Replace (str, "?", "")
str = Replace (str, "&", "")
str = Replace (str, "/", "")
str = replace (STR,VBCRLF, "")
GetFileName = str
End Function
sub savefile (str,fname)
'-------------------------This function is the function to save the contents of the stream-------------------
' On Error Resume Next
Set objstream = Server.CreateObject (' ADODB. Stream ")
'--------------set up the ADODB.stream object, you must have more than ADO 2.5 version---------
' objStream.Type = adTypeBinary
objStream.Type = 1
'-------------open in binary mode-------------------------------------
objStream.Open
Objstream.write str
'--------------------writes the string contents to the buffer--------------------------
' response. Write fname
Path attention
Objstream. SaveToFile "E:\webroot\pcqc\vip\UploadFile\cache\" &fname,2
' objstream. SaveToFile "d:\cache\" & Fname,adsavecreateoverwrite
'-------------------- Writes the buffered content to the file--------------------------
' response. BinaryWrite objstream. Read
Objstream. Close () the
Set objstream = Nothing
-----------------------Closes the object, releasing the resource-------------------------
' response. Write Err. Description
End Sub
function saveimage (from,tofile)
Dim Geturl,objstream,imgs
Geturl=trim (from)
Imgs=gethttppage (Geturl) ' Gets a picture of the content of the process
Set objstream = Server.CreateObject ("ADODB. Stream ")" To create the ADODB.stream object, you must have ADO 2.5 above version
objStream.Type = 1 ' Open in binary mode
objStream.Open
Objstream.write IMGs ' writes the string contents to the buffered
Objstream. SaveToFile Server.MapPath (ToFile), 2 '-writes the buffered content to the file
objstream. Close () ' closes object
set objstream=nothing
End Function
%>