有关网络地址的解析图例
2009-06-03 14:25
330 查看
这是一个很简单的例子,我讲解了如何根据一个网路的地址,解析各部分的内容 using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized; //需要预先添加对System.Web程序集的引用
using System.Web; namespace UrlParser
{
class Program
{
static void Main(string[] args)
{
string url = "http://www.xizhang.com/subdir/somepage.aspx?id=1&page=2"; Uri uri = new Uri(url); Console.WriteLine("协议(Protocal):{0}", uri.Scheme);
Console.WriteLine("主机名(Host):{0}", uri.Host);
Console.WriteLine("端口号(Port):{0}", uri.Port); Console.WriteLine("绝对路径(AbsolutePath):{0}", uri.AbsolutePath);
Console.WriteLine("本地地址(LocalPath):{0}", uri.LocalPath); Console.WriteLine("查询字符串(Query):{0}", uri.Query);
Console.WriteLine("带查询字符串的地址(PathAndQuery):{0}", uri.PathAndQuery); Console.WriteLine("解析得到的查询键值对:");
NameValueCollection nvc = GetQueryStringParameters(uri.Query);
foreach (string item in nvc.Keys)
{
Console.WriteLine("键:{0},值:{1}", item, nvc[item]);
} Console.Read(); } private static NameValueCollection GetQueryStringParameters(string query)
{
NameValueCollection col = new NameValueCollection();
col = HttpUtility.ParseQueryString(query);
return col;
} }
} 下面是输出的结果
using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized; //需要预先添加对System.Web程序集的引用
using System.Web; namespace UrlParser
{
class Program
{
static void Main(string[] args)
{
string url = "http://www.xizhang.com/subdir/somepage.aspx?id=1&page=2"; Uri uri = new Uri(url); Console.WriteLine("协议(Protocal):{0}", uri.Scheme);
Console.WriteLine("主机名(Host):{0}", uri.Host);
Console.WriteLine("端口号(Port):{0}", uri.Port); Console.WriteLine("绝对路径(AbsolutePath):{0}", uri.AbsolutePath);
Console.WriteLine("本地地址(LocalPath):{0}", uri.LocalPath); Console.WriteLine("查询字符串(Query):{0}", uri.Query);
Console.WriteLine("带查询字符串的地址(PathAndQuery):{0}", uri.PathAndQuery); Console.WriteLine("解析得到的查询键值对:");
NameValueCollection nvc = GetQueryStringParameters(uri.Query);
foreach (string item in nvc.Keys)
{
Console.WriteLine("键:{0},值:{1}", item, nvc[item]);
} Console.Read(); } private static NameValueCollection GetQueryStringParameters(string query)
{
NameValueCollection col = new NameValueCollection();
col = HttpUtility.ParseQueryString(query);
return col;
} }
} 下面是输出的结果
相关文章推荐
- 有关网络地址的解析图例
- 网络层 - 因特网中的网络层(IP控制协议、地址解析)
- 深入理解iputils网络工具-第5篇 arping:地址解析程序
- DNS 域名解析 (主机解析 地址解析 ) 网络协议
- 解析网络视频真实地址
- 深入理解iputils网络工具-第5篇 arping:地址解析程序
- 关于网络地址划分的解析
- 全面解析有关网上邻居的内幕_网络管理
- 网络层------地址解析ARP协议
- 计算机网络学习总结----IP地址分类+子网划分+地址解析
- Python网络编程 4.2 IPv6简介与现代地址解析--getaddrinfo()方法的使用
- 网络层地址I解析协议ARP
- 深入理解iputils网络工具-第6篇 rarpd:逆地址解析程序
- 解析网络地址webview加载地址
- 【RL-TCPnet网络教程】第23章 RL-TCPnet之地址解析协议ARP
- virtualbox虚拟机(Ubuntu16.04)在网络设置有NAT和only主机两块网卡时,安装ssh显示无法解析地址的问题解决
- 【网络】无法解析服务器的DNS地址?;能登陆QQ,无法打开网页
- 解析网络地址webview加载地址
- 网络地址结构体解析
- Android开发中定位解析(GPS定位、网络定位、位置地址解析)