任何人都可以请帮助我将这段代码片段转换为它的.NET内核等效?WebClient(.net 4.6)到HttpClient(.net核心)
Uri uri = new Uri(url);
string filename = System.IO.Path.GetFileName(uri.LocalPath);
string extension = Path.GetExtension(filename);
string tempFilepath = Path.GetTempFileName() + extension;
try
{
WebClient webClient = new WebClient();
webClient.DownloadFile(url, tempFilepath);
if (new FileInfo(tempFilepath).Length > 0)
{
return tempFilepath;
}
else {
return null;
}
}
catch (WebException e)
{
return null;
}
catch (NotSupportedException e)
{
return null;
}
实际上,此代码以前是在.NET 4.6中写入的应用程序中。然后前一段时间,我们停止使用该应用程序。现在我正在开发另一个.net核心应用程序,并且将完成同样的事情。所以我想知道我将如何使用.net核心来做到这一点? 什么是HttpClient中DownloadFile方法的替代方法?
不知道为什么人们都反对投票这一点。 @Syed尽自己的努力编写代码,这个问题是关于.NET Core框架的变化,而不是要求分发。 –