Skip to content

Instantly share code, notes, and snippets.

@GeekaholicLin
Last active July 15, 2016 11:47
Show Gist options
  • Save GeekaholicLin/0ae876be3dbfe9098ebcb5571e3272d9 to your computer and use it in GitHub Desktop.
Save GeekaholicLin/0ae876be3dbfe9098ebcb5571e3272d9 to your computer and use it in GitHub Desktop.
区分URL、URI、和 URN

参考(referrence):
http://stackoverflow.com/questions/176264/what-is-the-difference-between-a-uri-a-url-and-a-urn#answer-1984225
http://web.jobbole.com/83452/
https://tools.ietf.org/html/rfc3986 ---[Uniform Resource Identifier (URI)]
https://tools.ietf.org/html/rfc1738 ---[Uniform Resource Locator (URL)]
http://www.cnblogs.com/hust-ghtao/p/4724885.html

URIs identify and URLs locate; however, locators are also identifiers, so every URL is also a URI, but there are URIs which are not URLs.--from stackoverflow

URL(Uniform Resource Locator)与URN(Uniform Resource Name)都是URI(Uniform Resource Identifier)的子集,个人认为,从名称上再加上一些理解,可以很清楚地区别他们。

以生活中的例子和Web技术中的例子为例:

URL是一种URI,它标识一个互联网资源,并指定对其进行操作或取得该资源的方法。它相当于图书馆中书架的编号(当然还有图书馆的地址)。某种程度上可以简单地概括为"获取路径+获取方法(协议)"。 URL的语法为 <scheme>:<scheme-specific-part>

语法说明:

A URL contains the name of the scheme being used () followed by a colon and then a string (the ) whose interpretation depends on the scheme.

由此可以看出,它必须提供协议(访问机制),比方说file,ftp,http等,常用于网络资源, 当然也有数据库等本地资源,关键看其是否提供访问机制。

URLs are used to locate resources, by providing an abstract identification of the resource location. Having located a resource, a system may perform a variety of operations on the resource, as might be characterized by such words as access, update, replace, find attributes. In general, only the access method needs to be specified for any URL scheme.

而URN可以允许人们在不指出其位置和获得方式的情况下谈论该资源,即使没有地址,但是它本身有唯一的标识。通过唯一的标识,我们可以知道那个是什么。URN对应的是书的ISBN编号(假设图书馆中是以ISBN来排列同类书籍),(事实上URN在标识唯一书目的ISBN系统上使用比较多,在Web资源定位使用较少)。 URN的语法是urn:<NID>:<NSS>

而URI包括以上两个,只要能够唯一地标识出来的资源(资源可以是具体的也可以抽象的,并且不仅仅局限于互联网),都可以说这个标识是 URI。 绝对URI的语法为: scheme:[//[user:password@]host[:port]][/]path[?query][#fragment],而URI引用(relative referrence)为绝对URI的一部分或者空字符串

官方对于三者的区别,描述如下:

A URI can be further classified as a locator, a name, or both. The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in addition to identifying a resource, provide a means of locating the resource by describing its primary access mechanism (e.g., its network "location")(为了标识资源,提供一种通过描述资源的主要获取途径而定位资源的手段,即URL). The term "Uniform Resource Name" (URN) has been used historically to refer to both URIs under the "urn" scheme [RFC2141], which are required to remain globally unique and persistent even when the resource ceases to exist or becomes unavailable, and to any other URI with the properties of a name.(URN用来描述资源,需要保持全局唯一。它的主要特定在于,它依然存在,即使资源本身不再存在[私以为'资源无法获取更好'])


讲了那么多,来一些例子:

example:

  • http://en.wikipedia.org/wiki/URI#Examples_of_URI_references (绝对URI;也是URL,能通过路径和访问机制获取资源)
  • #frag01(URI引用[Relative Reference],也就是基本URI的部分,为了区分绝对URI有专门的名称)
  • /relative/URI/with/absolute/path/to/resource.txt(URI引用,不是URL,无协议部分)
  • urn:issn:1535-3613(URI,URN)

瞎BB那么久,花那么大工夫区别他们有什么用处?

http://www.cnblogs.com/gaojing/archive/2012/02/04/2413626.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment