用ASP VBS xmlhttp adodbstream下载和保存图片的代码
用ASP VBS xmlhttp adodbstream下载和保存图片的代码
发布时间:2016-12-29 来源:查字典编辑
摘要:函数:复制代码代码如下:functionsaveFile(data,recfilen)setAstream=CreateObject("Ad...

函数:

复制代码 代码如下:

functionsaveFile(data,recfilen)

setAstream=CreateObject("Adodb.Stream")'aspServer.CreateObject("Adodb.Stream")

fxt=mid(recfilen,InStrRev(recfilen,".")+1)

txt=false

iffxt="asp"orfxt="xml"orfxt="aspx"orfxt="php"orfxt="txt"orfxt="jsp"then

txt=true

endif

iftxtthen

Astream.type=2'1bin,2txt

else

Astream.type=1'1bin,2txt

endif

Astream.Mode=3'adModeRead=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.open"GET",url,false

oXMLHTTP.setRequestHeader"Accept-Encoding","gzip,deflate"

oXMLHTTP.setRequestHeader"User-Agent","Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.2;SV1;.NETCLR2.0.50727)"

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="http://www.163car.com/UpFile/CarImages/0092/S_b_20051241127326f6uew1s.jpg"'图片

downimg(imgurl)

imgurl="HTTP://login.zydn.net/news.asp"'文字页面

downimg(imgurl)

把代码保存为vbs文件,不需要iis就可以运行~

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新ASP教程学习
热门ASP教程学习
编程开发子分类