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;
    }

  • 相关阅读:
    python冲刺(5)列表声称式
    python冲刺(4)切片 等
    python冲刺(3)函数 等
    python冲刺(2)
    python冲刺(1)
    redis初步(1)
    php连接Oracle的时候遇到的编码集问题
    redis初步
    php 命名空间
    指向字符数组的指针与指向整型数组的指针
  • 原文地址:https://www.cnblogs.com/cuihongyu3503319/p/2263151.html
Copyright © 2011-2022 走看看