S.l.e!ep.¢%

像打了激速一样,以四倍的速度运转,开心的工作
简单、开放、平等的公司文化;尊重个性、自由与个人价值;
posts - 1098, comments - 335, trackbacks - 0, articles - 1
  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

asp下载文件并以二进制流输出

Posted on 2009-09-21 14:34 S.l.e!ep.¢% 阅读(577) 评论(0)  编辑 收藏 引用 所属分类: HTML

<%
    ref = Request.QueryString("ref")
    go = Request.QueryString("goto")

    iF ref = "" then
       response.write "ref 为空"
       response.end
    End if

    iF go = "" then
       response.write "goto为空"
       response.end
    End if
  
    url = go   
    strUrl = split(url,"/")
    for i=1 to ubound(strurl)
    FileName = strurl(i)
    next
   
    ContentType = "application/octet-stream"  
    Response.AddHeader "Content-Disposition", "attachment; filename=" + FileName + ";"   
    Response.ContentType = ContentType  
    Response.BinaryWrite GethttpFile(url)

    Response.Flush  
    Response.BinaryWrite StrToBin(ref)
    Response.Flush
    response.Clear()  

    response.end

    function StrToBin(str)
        dim curChr, curAsc, low, high
        dim i
        for i=1 To Len(str)
            curChr = Mid(str, i, 1)
            curAsc = Asc(curChr)
            'asc对中文字符求出来的值可能为负数,
            '加上65536就可求出它的无符号数值
            '-1在机器内是用补码表示的0xffff,
            '其无符号值为65535,65535=-1+65536
            '其他负数依次类推。
       
            if curAsc < 0 then
                curAsc = curAsc + 65535
            end if
           
            '对中文的处理:把双字节低位和高位分开
            if curAsc > 255 then
                low = Left(Hex(Asc(curChr)), 2)
                high = Right(Hex(Asc(curChr)), 2)
                StrToBin = StrToBin & ChrB("&H" & low) & ChrB("&H" & high)
            else
                StrToBin = StrToBin & ChrB(AscB(CurChr))
            end If
        next
    end function

    Function GethttpFile(Url)
        On Error Resume Next
        Dim Http
        Set Http=Server.Createobject("MSXML2.XmlHttp")
        Http.Open "Get",Url,False
        Http.Send
        If Http.Readystate<>4 Then
            response.write "读取失败: " + Url
            response.end
            Exit Function
        end if       
 
        GethttpFile = Http.Responsebody
        Set Http=Nothing
        If Err.Number<>0 Then Err.Clear
    End Function

%>


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理