亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

統一資源標志符-URI

URI,統一資源標志符(Uniform Resource Identifier, URI),標識了網絡中的某個對象或者集合。它可以是 Web 系統中的某個圖片地址,也可以是某個人的郵箱地址。下面我們將詳細了解 URI 的定義,格式,以及 URI 和 URL 的區別。

1. URI 定義

1.1 什么是RFC

RFC 是一個文檔,這個文檔有點大也足夠權威,以至于有人稱它是互聯網界的圣經。里面收錄了互聯網開發中的各種協議規范,對 URI 的定義在 RFC2396 也有對應的記錄。

Tips:RFC 文件是由 Internet Society(ISOC)贊助發行的,由一個個編號排列起來的文件。

1.2 RFC2396 解讀

RFC2396 的規約中對 URI 3 個單詞有如下定義:
Uniformity

Uniformity provides several benefits: it allows different types of
resource identifiers to be used in the same context, even
when the mechanisms used to access those resources may differ; it allows uniform semantic interpretation of common syntactic conventions across different types of resource identifiers; it allows introduction of new types of resource identifiers without interfering with the way that existing identifiers are used; and, it allows the identifiers to be reused in many different contexts, thus permitting new applications or protocols to leverage a pre-existing, large, and widely-used set of resource identifiers.

有一個統一的格式,這個格式允許我們訪問不同類型的資源,即使他們有同樣的上下文,并且這個格式是可擴展的,允許后面有新的協議加入。

Resource

A resource can be anything that has identity. Familiar examples include an electronic document, an image, a service (e.g., “today’s weather report for Los Angeles”), and a collection of other resources. Not all resources are network “retrievable”; e.g., human beings, corporations, and bound books in a library can also be considered resources. The resource is the conceptual mapping to an entity or set of entities, not necessarily the entity which corresponds to that mapping at any particular instance in time. Thus, a resource can remain constant even when its content—the entities to which it currently corresponds—changes over time, provided that the conceptual mapping is not changed in the process.

資源是任何可標識的東西,文件圖片甚至特定某天的天氣等,它是一個或者一組實體的概念映射。

Identifier

An identifier is an object that can act as a reference to something that has identity. In the case of URI, the object is a sequence of characters with a restricted syntax.

表示可標識的對象。也稱為標識符。

2. 格式

scheme 一般指的是協議,URI 的通用格式并沒有太多限制,一般是如下,以 scheme 開頭,冒號 “:” 分隔開。

  <scheme>:<scheme-specific-part>

雖然 URI 的格式沒怎么限制,但是不同 scheme 一般會遵循下面的格式來定義。

<scheme>://<authority><path>?<query>

以 scheme = http 加以說明:

 http://www.imocc.com:80/index.htm?id=3937

Http 的 <authority>模塊一般不會寫在路徑上面,即使是 Basic Authorization 也是將用戶名密碼 base64(user:passwd) 寫在 head 里面。

下面的例子說明 RUI 的一般用法:

3. URL

通過前面我們知道 URI 是網絡中用于標識某個對象的規約,URI 包含了多個 <scheme>,所以 URL 是 scheme = http 的 URI。URL 是 URI 的子集,只要是 URL 一定就是 URI ,反過來不成立。

URL 和 URI 只差了一個字母,Location 和 Identifier:
Location:定位,著重強調的是位置信息;
Identifier:標識,只是一種全局唯一的昵稱。

舉例:

美國是一個國家,它只是一種標識,通過美國這兩個字我們無法知道這個國家在哪里。如果這個標識換成了經緯度,那我們就能知道這個經緯度對應的是美國,并且知道美國所處的位置信息。

4. 小結

本小節主要學習了 URI 的概念,并且區分出了大家容易誤解的 URI 和 URL 的區別。在新版的 Http/2.0 文檔中已經將 URL 修改成了 URI,可能也是怕大家混淆,不過在詳細地了解清楚后,改不改問題都不大了。