我正在用c#编写一个应用程序,是否有办法通过仅为我的程序提供URL来下载HTML页面.敌人示例我的程序将获取URL www.google.com并下载HTML页面?
使用WebClient类.
这是从msdn doc页面上的示例中提取的:
using System;
using System.Net;
using System.IO;
public static string Download (string uri)
{
WebClient client = new WebClient ();
Stream data = client.OpenRead (uri);
StreamReader reader = new StreamReader (data);
string s = reader.ReadToEnd ();
data.Close ();
reader.Close ();
return s;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16739 次 |
最近记录: |