如何将xmlhttp.ResponseBody的数据直接写入一文件中?

annkie 2005-08-12 08:02:45
我使用VBS编码,向把xmlhttp.ResponseBody的内容直接写入一文件中,但使用FSO写的时候会提示
“无效的过程调用或参数”,而经过bytes2BSTR转化后可以正常写入文件,但速度太慢无法满足需要,我希望是xmlhttp.ResponseBody的raw data 直接写入文件,请问有什么办法没有?谢谢!
由于上论坛时间有限,请有解决方案的兄弟尽量抄一份到我的信箱,感激不尽。 annkieliu@yahoo.com.cn
...全文
763 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
woodeye 2005-12-22
  • 打赏
  • 举报
回复
XMLHTTP取得了图片的内容要保存,给人一种感觉是用FSO来作就可以了,但实际上不行,这样保存程序就会出错,因为FSO不支持流式的文件,所以我们要调用另一个对象:ADO.STREM。具体的过程如下:
(一个小偷程序的一部分,自己看一下吧)
<%
'Response.Buffer = True
Server.ScriptTimeOut=999999999
Function AutoCreateFolder(strPath) ' As Boolean
On Error Resume Next
Dim astrPath, ulngPath, i, strTmpPath
Dim objFSO
If InStr(strPath, "\") <=0 Or InStr(strPath, ":") <= 0 Then
AutoCreateFolder = False
Exit Function
End If
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists(strPath) Then
AutoCreateFolder = True
Exit Function
End If
astrPath = Split(strPath, "\")
ulngPath = UBound(astrPath)
strTmpPath = ""
For i = 0 To ulngPath
strTmpPath = strTmpPath & astrPath(i) & "\"
If Not objFSO.FolderExists(strTmpPath) Then
' 创建
objFSO.CreateFolder(strTmpPath)
End If
Next
Set objFSO = Nothing
If Err = 0 Then
AutoCreateFolder = True
Else
AutoCreateFolder = False
End If
End Function


function getHTTPPage(url)
on error resume next
dim http
set http=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法来获得图片的内容
Http.open "GET",url,false
Http.send()
if Http.readystate<>4 then
exit function
end if
getHTTPPage=Http.responseBody
set http=nothing
if err.number<>0 then err.Clear
end function



function saveimage(from,tofile)
on error resume next
dim geturl,objStream,imgs
geturl=trim(from)
imgs=gethttppage(geturl)'取得图片的具休内容的过程
Set objStream = Server.CreateObject("ADODB.Stream")'建立ADODB.Stream对象,必须要ADO 2.5以上版本
objStream.Type =1'以二进制模式打开
objStream.Open
objstream.write imgs'将字符串内容写入缓冲
objstream.SaveToFile server.mappath(tofile),2'-将缓冲的内容写入文件
objstream.Close()'关闭对象
set objstream=nothing
end function


Set rsflash = Server.CreateObject("ADODB.Recordset")
sqlflash = "SELECT * FROM Flash Order By ID DESC"
rsflash.Open sqlflash,Conn,1,1
'Response.Write rsflash.RecordCount
For p = 1 To 1000
Response.Write rsflash("Flash_File")
Response.Write ("<p>")
url="http://flash.9you.com"
flashurl = rsflash("Flash_File")
FileName= Right(flashurl,Len(flashurl)-InStrRev(flashurl,"/")) '取文件名
PathName= Mid(Left(flashurl,InStrRev(flashurl,"/")),len(url)+1)
SavePath =Replace(Request.ServerVariables("APPL_PHYSICAL_PATH") & PathName,"/","\")

If AutoCreateFolder(SavePath) Then
Response.Write "创建文件夹成功"
Else
Response.Write "创建文件夹失败"
End If

tofile = PathName & FileName

pppp = saveimage(flashurl,tofile)

rsflash.movenext
next
rsflash.close
set rsflash = nothing
%>
孟子E章 2005-12-22
  • 打赏
  • 举报
回复
<%
Set x = Server.CreateObject("Msxml2.XMLHTTP")
x.Open "GET","http://community.csdn.net/Expert/topic/4206/4206101.xml?temp=.2156488",false
x.send

If x.status=200 Then
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type=1

S.Write x.responseBody
S.savetoFile Server.mappath(".") & "\x.xml",2
S.close
Response.Redirect "x.xml"
End If
%>
孟子E章 2005-12-22
  • 打赏
  • 举报
回复
<%
Set x = Server.CreateObject("Msxml2.XMLHTTP")
x.Open "GET","http://community.csdn.net/images/CSDN_logo.GIF",false
x.send

If x.status=200 Then
Set s = Server.CreateObject("ADODB.Stream")
s.Open
s.Type = 1
S.Write x.responseBody
S.savetoFile Server.mappath(".") & "\x.gif",0
S.close
Response.Redirect "x.gif"
End If
%>
孟子E章 2005-12-22
  • 打赏
  • 举报
回复
ado stream+xmlhttp就可以了
ffyd2000 2005-12-22
  • 打赏
  • 举报
回复
ado stream应该是写流的首选吧
jspadmin 2005-12-22
  • 打赏
  • 举报
回复
fso里使用流的方式写入,应该可以
jspadmin 2005-12-22
  • 打赏
  • 举报
回复
不转化就写入文件,好象是比较难办
创造奇迹9999 2005-08-13
  • 打赏
  • 举报
回复
用FSO写应该没问题的吧!

呀者试下这个ADODB.Stream
annkie 2005-08-13
  • 打赏
  • 举报
回复
up

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧