2014-01-30 73 views

回答

0

您应使用此代码:

using System.Net; 
//... 
using (WebClient webClient = new WebClient()) 
{ 
    client.DownloadFile("http://yoursite.com/page.html", @"C:\localfile.html"); 

    // Or you can get the file content without saving it: 
    string htmlCode = client.DownloadString("http://yoursite.com/page.html"); 
    //... 
} 

在htmlCode你会得到HTML源代码预期和文本查看器中显示它。

+0

client.DownloadFile(“http://yoursite.com/page.html”,@“C:\ localfile.html”); 但该网址应该是动态的。如何从打开的浏览器窗口中获取网址? – user3252447

+0

你可以通过ajax或post调用发送给服务器(假设使用jquery或任何其他适当的JavaScript库)。您将通过javascript中的window.location.href找到当前的URL。 –