WebClient保存文件

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lixiaoer757/article/details/80340169

使用System.Net.WebClient类

using (WebClient client = new WebClient())
{
    string tmpName = "要保存的文件路径";
    //client.Headers.Add("Cookie", WebApiClientConfiguration.TokenCookieName + "=" + ClientPublicData.LoginToken + ";");
    //Uri uri = new Uri(WebApiClientConfiguration.MyWebApiBaseAddress + "File/Download?docGuid=" + doc.DocGuid);

    Uri uri = new Uri(HttpContext.Current.Request.Url.Authority + "/AfterLoanAPI/CustLoanDoc/Download?docGuid=" + doc.DocGuid);
    try
    {
        client.DownloadFileTaskAsync(uri, tmpName);
    }
    catch (Exception ex)
    {
        //throw new Exception(ex.Message);
        Logger.Error(ex);
        result.ErrCode = 1;
        result.ResultMsg = "获取文件失败!";
    }
}

阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页