async-Task


public async Task<ActionResult> DownloadImage(string mediaId)
        {
            string accessToken = string.Empty;
            string file = string.Empty;
            string content = string.Empty;
            string strpath = string.Empty;
            string savepath = string.Empty;
            string stUrl = string.Empty;

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(stUrl);

            req.Method = "GET";
            await new Task(() =>
            {
                HttpWebResponse myResponse = (HttpWebResponse)req.GetResponse();

                strpath = myResponse.ResponseUri.ToString();
                WebClient mywebclient = new WebClient();
                savepath = Server.MapPath("~/Upload/UploadImage") + "\\" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + (new Random()).Next().ToString().Substring(0, 4) + ".jpg";
                ///C:inetpub\wwwroot\Upload\UploadImage
                try
                {
                    mywebclient.DownloadFile(strpath, savepath);
                    file = savepath.Substring(18);
                }
                catch (Exception ex)
                {
                    savepath = ex.ToString();
                }
            });

            return Json(new { Link = file }, JsonRequestBehavior.AllowGet);
        }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM