Use ASP remote acquisition content

xiaoxiao2021-03-06  113

Use ASP remote acquisition content

'---------- Remote acquisition content, and exist content on local computers, including any file! ---------- '--------------- Using XMLHTTP and Adodb.Stream, Cool! Absolute original! ----------------- Error Resume next'set the content type to the specificift That you are sending.'Response.contettype = "image / jpeg" --- --------------------------------------------- ------------

Path = Request.QueryString ("p") spath = pathif Left (LCase (Path), 7) <> "http: //" "------------- If there is no HTTP in front Local files, handed over to localfile processing ----------- Localfile (PATH) ELSE '------------------- Otherwise, for remote files, Hand it to Remotefile processing ---------------- Remotefile (PATH) end if'Response.write err.description

Sub localfile (path) '------------------ If you are a local file, simple jump to this page ------------- ------ Response.Redirect Pathend Sub

Sub Remotefile (Spath) '------------------------- Handle remote file function --------------- --------------- filename = getFilename (spath) '------------ GetFileName is a file name process for converting addresses to qualified file name ---- --------- FileName = Server.MapPath ( "/ UploadFile / Cache /" & FileName) Set objFso = Server.CreateObject ( "Scripting.FileSystemObject") 'Response.Write fileNameif objFso.FileExists (FileName) Then '-------------- Check if the file has been accessed, if so, simply jump ------------ Response.Redirect "/ uploadFile / Cache / "& GetFileName (PATH) ELSE '--------------- Otherwise, use the getBody function to read ----------------- ----- 'response.write path = getBody (path)' ----------------- use binary methods to write on the browser --------- ----------------- Response.binaryWrite TRESPONSE.FLUSH '----------------- Output buffer ------- ----------------------------------- Savefile T, getFilename (PATH) ------- ----------- Cache the file to the local path to wait for the next access ----------- end if set objfso = nothingend subj

Function GetBody (URL) '---------------------- This function is a function of remote acquisition content ------------- -------- 'On Error Resume Next'Response.write Urlset Retrieval = CreateObject ("Microsoft.xmlhttp")' --------------------- - Establish XMLHTTP objects ----------------------------- with retrieval .open "get", url, false, "" " '------------------ Use GET, asynchronous methods to send ---------------------. Send 'getbody = .responseTextGetBody = .RESPONSEBODY' ----------------------------------- --------- end with set retrieval = Nothing 'response.write err.description End FunctionFunction getFileName (STR)' --------------------- ---- This function is a qualified file name function ------------------ str = Replace (LCase (STR), "http: //", "" Str = Replace (LCase (STR), "//", "/") Str = Replace (STR, "/", "") str = replace (str, vbcrlf, "") getFileName = streven

Sub Savefile (STR, FNAME) '------------------------- This function is a function of the flow content store -------- --------- 'On Error ResMe NextSet Objstream = Server.createObject ("AdoDb.Stream")' -------------- Establish an adoDb.stream object, must To have an ADO 2.5 or above ------- Objstream.Type = adtypebinary '------------- Take binary mode ------------- ------------------------ Objstream.OpenObjstream.write str '------------------- - Write string contents into buffer ------------------------ 'response.write fnameObjstream.savetofile "C: / inetpub / myweb / uploadfile / cache / "& fname, adsavecreateoverwrite" -------------------- Write the buffered content into the file -------------- ------------ 'response.binarywrite objstream.read objstream.close () set objstream = Nothing' ------------------- - Close the object, release resources ----------------------- 'response.write err.description end sub%>

转载请注明原文地址:https://www.9cbs.com/read-100304.html

New Post(0)