现在我正在尝试下载某个 HTML 网站的页面源代码。我试图保留默认的库,所以我使用的是 DownloadFileAsync。我通过 DownloadFileAsync 的 Uri 存储在 AbsoluteUri 设置下,我猜你可以调用它,但是当调用 DownloadFileAsync 时,它使用我不知道如何设置的 Uri 的 AbsolutePath,并自动设置为网站索引页面,这不是我想要的是。所以我想知道如何更改 AbsolutePath 或使用 AbsoluteUri 作为 URL DownloadFileAsync 使用。就像我说的,我想继续使用默认库,但如果有人可以诚实地推荐一个好的简单的外部库,我会试一试。
代码
void Downloader::GetHTML(CString HTML)
{
string Temp, Data="";
WebClient^ myClient = gcnew WebClient;
WebProxy wProxy;
myClient->Proxy = wProxy.GetDefaultProxy();
myClient->Credentials = CredentialCache::DefaultCredentials;
String^ HTML = gcnew String (GetSourceHTML(HTML));
Uri^ Base = gcnew Uri("http://walmart.com");
Uri^ Link = gcnew Uri(Base,HTML);
myClient->DownloadFileAsync(Link,"C:\\Users\\me\\Desktop\\Test2.txt");
}