用ASP VBS xmlhttp adodbstream下载和保存图片的代码
2018-09-06 12:59
函数:
复制代码 代码如下:
functionsaveFile(data,recfilen)
setAstream=CreateObject(Adodb.Stream)aspServer.CreateObject(Adodb.Stream)
fxt=mid(recfilen,InStrRev(recfilen,.)+1)
txt=false
iffxt=asporfxt=xmlorfxt=aspxorfxt=phporfxt=txtorfxt=jspthen
txt=true
endif
iftxtthen
Astream.type=21bin,2txt
else
Astream.type=11bin,2txt
endif
Astream.Mode=3adModeRead=1
adModeReadWrite=3
adModeRecursive=4194304
adModeShareDenyNone=16
adModeShareDenyRead=4
adModeShareDenyWrite=8
adModeShareExclusive=12
adModeUnknown=0
adModeWrite=2
Astream.open
Astream.CharSet=GB2312
Astream.LoadFromFile(recfilen)装载文件
Assp=Astream.size
Astream.Position=0装载文件时设置为Assp
Astream.Writetexttmpstr00,1
iftxtthen
data=bytes2bstr(data)
Astream.Writetextdata,1
else
Astream.Writedata
endif
Astream.SaveToFilerecfilen,2
Astream.close
endfunction
Server.
functiondownimg(url)
setoXMLHTTP=CreateObject(Microsoft.XMLHTTP)aspServer.CreateObject(Microsoft.XMLHTTP)
data_got=
oXMLHTTP.openGET,url,false
oXMLHTTP.setRequestHeaderAccept-Encoding,gzip,deflate
oXMLHTTP.send
rtstatus=oXMLHTTP.status
data_got=oXMLHTTP.responsebody
filename=mid(url,InStrRev(url,/)+1)
ifrtstatus=200then
data_got=oXMLHTTP.responsebody
saveFiledata_got,filename
else
data_got=
endif
setoXMLHTTP=nothing
endfunction
functionbytes2bstr(vin)二进制转化为汉字
strreturn=
fori=1tolenb(vin)
thischarcode=ascb(midb(vin,i,1))
ifthischarcode<&h80then
strreturn=strreturn&chr(thischarcode)
else
nextcharcode=ascb(midb(vin,i+1,1))
strreturn=strreturn&chr(clng(thischarcode)*&h100+cint(nextcharcode))
i=i+1
endif
next
bytes2bstr=strreturn
endfunction
使用方法:
复制代码 代码如下:
imgurl=图片
downimg(imgurl)
imgurl=文字页面
downimg(imgurl)
把代码保存为vbs文件,不需要iis就可以运行~
上一篇:ASP实现SQL备份、恢复
文章标题:用ASP VBS xmlhttp adodbstream下载和保存图片的代码
文章链接:http://soscw.com/essay/10798.html