C#网络编程
1. WebClient 类.............................................................................................................................................................................1
(1) WebClient 类的主要方法...............................................................................................................................................1
(2) DownloadData()方法......................................................................................................................................................1
(3) OpenRead()方法.............................................................................................................................................................1
(4) UploadData()方法...........................................................................................................................................................1
(5) 总结 WebClient 类..........................................................................................................................................................2
2. WebRequest 类与 WebResponse 类.........................................................................................................................................2
(1) WebRequest 类与 WebResponse 类简介.......................................................................................................................2
(2) 使用示例.........................................................................................................................................................................2
(3) WebRequest 类与 WebResponse 类的子类(继承结构)................................................................................................2
(4) HttpWebRequest 类与 HttpWebResponse 类使用示例.................................................................................................2
(5) 身份验证.........................................................................................................................................................................3
(6) 使用代理.........................................................................................................................................................................3
(7) 异步请求.........................................................................................................................................................................3
3. WebBrowser 控件.....................................................................................................................................................................3
(1) 使用 WebBrowser 控件..................................................................................................................................................3
(2) WebBrowser 控件常用属性、方法与事件...................................................................................................................4
4. 网络工具类(URL、IP、DNS)................................................................................................................................................4
(1) Uri 与 UriBuilder............................................................................................................................................................4
(2) IPAddress、IPHostEntry 与 Dns....................................................................................................................................5
(3) 解码与编码(Encoding)...................................................................................................................................................5
5. 底层的网络协议类..................................................................................................................................................................5
(1) Socket..............................................................................................................................................................................5
(2) NetworkStream、TcpClient 与 TcpListener...................................................................................................................6
(3) UdpClient........................................................................................................................................................................6
(4) SmtpClient.......................................................................................................................................................................7
作者:李志伟
时间:2014-02-07
1.WebClient 类
(1)WebClient 类的主要方法
DownloadXXX()方法:下载 URI 资源文件
OpenXXX()方法:打开 URI 资源流
UploadXXX()方法:上传资源到 URI
(2)DownloadData()方法
class Program
{
static void Main(string[] args)
{
WebClient web = new WebClient();
byte[] temp = web.DownloadData("http://www.baidu.com");//下载URI资源文件
string Response = Encoding.UTF8.GetString(temp);//解码
Console.WriteLine(Response);
Console.Read();
}
}
(3)OpenRead()方法
class Program
{
static void Main(string[] args)
{
WebClient web = new WebClient();
Stream st = web.OpenRead("http://www.baidu.com");//打开URI资源流
StreamReader sr = new StreamReader(st);
string Response = sr.ReadToEnd();
Console.WriteLine(Response);
Console.Read();
}
}
(4)UploadData()方法
class Program
评论3
最新资源