加载文件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;
}

原文地址:https://www.cnblogs.com/cuihongyu3503319/p/2263151.html