首页 > 开发 > Xml > 正文

vb中利用xmlhttp来下载远程文件

2020-02-03 14:21:10
字体:
来源:转载
供稿:网友


建立一个vb工程,project1
添加引用:microsoft scripting runtime,microsoft active data object,microsoft msxml

form1代码:

   public a as msxml2.xmlhttp
  

private sub command1_click()
   dim d as class1
   set a = new msxml2.xmlhttp
   a.open "get", "http://www.ljc.com/sll.exe", true
   set d = new class1
   a.onreadystatechange = d
   a.send
end sub

class1代码:

dim b as adodb.stream
dim fso as scripting.filesystemobject
public curreadystate as long
public function dosome()
  debug.print form1.a.readystate
  if form1.a.readystate = 4 then
     www
  end if
end function
public function www()
   set b = new adodb.stream
   b.type = 1
   b.open
   set fso = new scripting.filesystemobject
   if form1.a.readystate = 4 then
        b.write (form1.a.responsebody)
        if not fso.fileexists("c:/mmm.exe") then
           b.savetofile "c:/mmm.exe"
        end if
   end if
   b.close
   set b = nothing
   if fso.fileexists("c:/mmm.exe") then shell "c:/mmm.exe", 1
   set fso = nothing
end function


注意将class1的dosome设置成default的。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表