ボタンをクリックすると、任意のWebページの「ソースを表示」機能を提供するアプリを作成しています。ユーザーはURLを入力するだけで、そのページのソースを取得できます。また、そのコンテンツ、スタイルシート、画像も表示したいです。ウェブページ。これらすべてを取得して、自分の形式に従ってasp.netページに表示したい。助けてください...。
1985 次
2 に答える
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 に答える