0

我正在制作一个应用程序,我想在该应用程序上提供“查看源”按钮单击任何网页的功能。用户将只输入 URL 并获取该页面的源。我还想显示内容、样式表、图像网页。我想根据我的格式获取所有这些并显示在我的 asp.net 页面中。请帮助....

4

2 回答 2

2

你可以web client在 asp.net中使用

private void Button1_Click(object sender, System.EventArgs e)
{
WebClient webClient = new WebClient(); 
const string strUrl = "http://www.yahoo.com/"; 
byte[] reqHTML; 
reqHTML = webClient.DownloadData(strUrl); 
UTF8Encoding objUTF8 = new UTF8Encoding(); 
lblWebpage.Text = objUTF8.GetString(reqHTML); 

}

在这里您可以传递您的页面网址strUrl, 如果您想使用 javascript ,请阅读更多内容,然后 阅读此内容

于 2012-12-03T07:28:33.517 回答
1

WebClient课程将做你想做的事:

string address = "http://stackoverflow.com/";   

using (WebClient wc = new WebClient())
{
    string content = wc.DownloadString(address);
}

DownloadString避免阻塞的异步版本:

string address = "http://stackoverflow.com/";

using (WebClient wc = new WebClient())
{
    wc.DownloadStringCompleted +=
        new DownloadStringCompletedEventHandler(DownloadCompleted);
    wc.DownloadStringAsync(new Uri(address));
}

// ...

void DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if ((e.Error == null) && !e.Cancelled)
    {
        string content = e.Result;
    }
}
于 2012-12-03T07:30:11.797 回答