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

<%
    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

%>

你可能感兴趣的:(asp下载文件并以二进制流输出)