有关网络地址的解析图例

该篇文章是我于2009年6月10日通过自己编写的工具,批量从位于在博客园的博客站点(http://chenxizhang.cnblogs.com)同步而来。文章中的图片地址仍然是链接到博客园的。特此说明!

陈希章

原文地址:http://www.cnblogs.com/chenxizhang/archive/2009/06/03/1495331.html
原文标题:有关网络地址的解析图例
原文发表:2009/6/3 6:25:00

这是一个很简单的例子,我讲解了如何根据一个网路的地址,解析各部分的内容

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;
        } 

    }
}

下面是输出的结果

image

作者:陈希章
出处:http://blog.csdn.net/chen_xizhang
本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值