陋室铭
永远也不要停下学习的脚步(大道至简至易)

posts - 995,comments - 402,trackbacks - 24

        string url = "http://www.youdao.com/n/alliance/images/logo_youdao.gif";
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
        request.Timeout = 150000;

        HttpWebResponse response = (HttpWebResponse)request.GetResponse();
        WebHeaderCollection whc = response.Headers;
        Stream stream = response.GetResponseStream();

        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("logo_youdao.gif", Encoding.UTF8));


        int buffer = 1024;
        int alreadyRead = 0;
        do
        {
            byte[] bytes = new byte[buffer];
            alreadyRead = stream.Read(bytes, 0, buffer);
            Response.BinaryWrite(bytes);
            Response.Flush();
        }
        while (alreadyRead > 0);
        Response.End();
        Response.Close();

posted on 2011-11-25 13:55 宏宇 阅读(24) 评论(0) 编辑 收藏