任何人都可以請幫助我將這段代碼片段轉換爲它的.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框架的變化,而不是要求分發。 –