如何更改我的 C# 下载方法,以便它从重定向到它的给定链接获取最终下载链接。现在我有兴趣获得 CCleaner 的最后一个便携式版本,可以使用浏览器从https://www.ccleaner.com/ccleaner/download/portable获取。
这是我目前的下载方法:
public void downloadFile(String address, String filename)
{
WebClient down = new WebClient();
down.Headers.Add(HttpRequestHeader.UserAgent,"Mozilla/5.0 (compatible; http://example.org/)");
down.DownloadFileAsync(new Uri(address), filename);
}
当然,在给定的链接上使用它会导致下载一个似乎是 html 页面本身的文件。我的项目是并且需要是 net3.5 并且下载必须是异步的。知道我怎么能做到这一点吗?