asp获取远程文件并保存
[ 2007-04-02 14:38:20 | 作者: admin ]
asp保存远程文件的简单函数
将页面静态化,生成html页面函数
评论Feed: http://blog.xg98.com/feed.asp?q=comment&id=834
Sub SaveRemoteFile(LocalFileName,RemoteFileUrl)
Dim StreamObj,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set StreamObj = Server.CreateObject("Adodb.Stream")
With StreamObj
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set StreamObj = Nothing
End Sub
Dim StreamObj,Retrieval,GetRemoteData
Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
With Retrieval
.Open "Get", RemoteFileUrl, False, "", ""
.Send
GetRemoteData = .ResponseBody
End With
Set Retrieval = Nothing
Set StreamObj = Server.CreateObject("Adodb.Stream")
With StreamObj
.Type = 1
.Open
.Write GetRemoteData
.SaveToFile Server.MapPath(LocalFileName),2
.Cancel()
.Close()
End With
Set StreamObj = Nothing
End Sub
将页面静态化,生成html页面函数
<%
'定义xmlhttp
function GetXmlText(Url)
dim GetXmlHttp
set GetXmlHttp=server.Createobject("Microsoft.XMLHTTP")
GetXmlHttp.open "Get",url,false,"","" GetXmlHttp.Send
'GetXmlText=GetXmlHttp.Responsetext
GetXmlText=GetXmlHttp.ResponseBody
set GetXmlHttp=Nothing
end function
'转换为字符
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'保存文件
Sub SaveToFile(strBody,File)
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Type = 2
.Open
.Charset = "GB2312"
.Position = objStream.Size
.WriteText = strBody
.SaveToFile Server.MapPath(File),2
.Close
End With
Set objStream = Nothing End Sub
%>
<%SaveToFile BytesToBstr(GetXmlText("http://127.0.0.1/index.asp"),"GB2312"),"index.htm")%>
'定义xmlhttp
function GetXmlText(Url)
dim GetXmlHttp
set GetXmlHttp=server.Createobject("Microsoft.XMLHTTP")
GetXmlHttp.open "Get",url,false,"","" GetXmlHttp.Send
'GetXmlText=GetXmlHttp.Responsetext
GetXmlText=GetXmlHttp.ResponseBody
set GetXmlHttp=Nothing
end function
'转换为字符
Function BytesToBstr(body,Cset)
dim objstream
set objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function
'保存文件
Sub SaveToFile(strBody,File)
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
With objStream
.Type = 2
.Open
.Charset = "GB2312"
.Position = objStream.Size
.WriteText = strBody
.SaveToFile Server.MapPath(File),2
.Close
End With
Set objStream = Nothing End Sub
%>
<%SaveToFile BytesToBstr(GetXmlText("http://127.0.0.1/index.asp"),"GB2312"),"index.htm")%>
[最后修改由 admin, 于 2007-04-02 14:47:14]

这篇日志没有评论。
此日志不可发表评论。