当前位置: 移动技术网 > IT编程>开发语言>Asp > 用ASP VBS xmlhttp adodbstream下载和保存图片的代码

用ASP VBS xmlhttp adodbstream下载和保存图片的代码

2017年12月12日  | 移动技术网IT编程  | 我要评论
函数:

复制代码 代码如下:

function savefile(data,recfilen) 
    set astream=createobject("adodb.stream")'asp server.createobject("adodb.stream") 
    fxt=mid(recfilen,instrrev(recfilen,".")+1) 
    txt=false 
    if fxt="asp" or fxt="xml" or fxt="aspx" or fxt="php" or fxt="txt" or fxt="jsp" then 
        txt=true 
    end if 
    if txt then 
        astream.type=2  '1 bin,2 txt 
    else 
        astream.type=1  '1 bin,2 txt 
    end if 
    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.writetext tmpstr00,1 
    if txt then 
        data=bytes2bstr(data) 
        astream.writetext data,1 
    else 
        astream.write data 
    end if 

    astream.savetofile recfilen,2 
    astream.close     
end function 
    'server. 

     
function downimg(url) 
    set oxmlhttp =createobject("microsoft.xmlhttp")'asp server.createobject("microsoft.xmlhttp") 
    data_got="" 
    oxmlhttp.open "get",url, false 
    oxmlhttp.setrequestheader "accept-encoding"," gzip, deflate"  
    oxmlhttp.setrequestheader "user-agent","mozilla/4.0 (compatible; msie 6.0; windows nt 5.2; sv1; .net clr 2.0.50727)"  
    oxmlhttp.send 
    rtstatus=oxmlhttp.status 
    data_got=oxmlhttp.responsebody 
    filename=mid(url,instrrev(url,"/")+1)     
    if rtstatus=200 then 
        data_got=oxmlhttp.responsebody 
        savefile data_got,filename 
    else 
        data_got="" 
    end if 
    set oxmlhttp =nothing 
end function 
function bytes2bstr(vin) '二进制转化为汉字 
    strreturn = ""  
    for i = 1 to lenb(vin)  
        thischarcode = ascb(midb(vin,i,1))  
        if thischarcode < &h80 then  
            strreturn = strreturn & chr(thischarcode)  
        else  
            nextcharcode = ascb(midb(vin,i+1,1))  
            strreturn = strreturn & chr(clng(thischarcode) * &h100 + cint(nextcharcode))  
            i = i + 1  
        end if  
    next  
    bytes2bstr = strreturn  
end function  

使用方法:
复制代码 代码如下:

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就可以运行~

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网