URI&Uribuilder

View Code
1 Uri uri = new Uri("http://tieba.baidu.com/f?kw=%D0%A1%BD%DB%B5%C6");
2 StringBuilder strb = new StringBuilder();
3 strb.AppendLine(uri.Query+"//查询信息");
4 strb.AppendLine(uri.AbsolutePath + "//获取绝对路径");
5 strb.AppendLine(uri.Scheme + "//获取协议名称");
6 strb.AppendLine(uri.Port + "//获取端口号");
7 strb.AppendLine(uri.Host + "//获取主机部分");
8 MessageBox.Show(strb.ToString());

结果:

 

UriBuilder:

View Code
1  UriBuilder uribuilder = new UriBuilder();
2 uribuilder.Host = "www.baidu.com";
3 uribuilder.Scheme = "http";
4 uribuilder.Port = 80;

uribuilder可以组装一个uri地址。

结果:http://www.baidu.com:80/

posted @ 2012-03-23 13:08  猪特曼  阅读(548)  评论(0编辑  收藏  举报