URI,是uniform resource identifier,统一资源标识符,用来唯一的标识一个资源。而URL是uniform resource locator,统一资源定位器,它是一种具体的URI,即URL可以用来标识一个资源,而且还指明了如何locate这个资源。而URN,uniform resource name,统一资源命名,是通过名字来标识资源。 也就是说,URI是以一种抽象的,高层次概念定义统一资源标识,而URL和URN则是具体的资源标识的方式。
简单演示构造方法:
Uri baseUri = new Uri("https://blog.csdn.net");
Uri myUri = new Uri(baseUri, "qq_36330228/article/details/70212771");
Console.WriteLine(myUri);
//结果:https://blog.csdn.net/qq_36330228/article/details/70212771
uri各部分获取属性:
Uri uriAddress = new Uri("https://blog.csdn.net/qq_36330228/article/details/70212771?id=1&name=zs#search");
Console.WriteLine(uriAddress.Scheme); //https
Console.WriteLine(uriAddress.Authority); //blog.csdn.net
Console.WriteLine(uriAddress.Host); //blog.csdn.net
Console.WriteLine(uriAddress.Port); //443
Console.WriteLine(uriAddress.AbsolutePath); //qq_36330228/article/details/70212771
Console.WriteLine(uriAddress.Query); //?id=1&name=zs
Console.WriteLine(uriAddress.Fragment); //#search