zoukankan      html  css  js  c++  java
  • 加载文件url下载

            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();

    ----------------------------------------------------------------------------------------------------------------

    protected void Page_Load(object sender, EventArgs e)
    {
    string URl="http://info-database.csdn.net/Upload/2010-12-10/728_90_ty1210.jpg";
    string ss = test(URl);
    }
    string test(string url)
    {
    string PathBigImg = Server.MapPath("~/WebImg/BigImg/") + DateTime.Now.ToString("yyMMddHHmmss") + System.IO.Path.GetExtension(url);

    WebClient wc = new WebClient();
    wc.DownloadFile(url, PathBigImg);

    return PathBigImg;
    }

  • 相关阅读:
    JAVA 桥接模式
    字模生成/提取原理
    const修饰指针
    BMP格式分析
    [转载]在.Net中使用SMTP发送邮件
    [转载]MD5加密解密
    四十二。java
    四十四。java
    四十一。复习第十二章内容
    三十六。文件流
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/2263151.html
Copyright © 2011-2022 走看看