URI学习笔记

来源:互联网 发布:域名认证失败 编辑:程序博客网 时间:2024/05/16 10:38

URI文法由URI协议名(例如“http”,“ftp”,“mailto”或“file”),一个冒号,和协议对应的内容所构成。特定的协议定义了协议内容的语法和语义,而所有的协议都必须遵循一定的URI文法通用规则,亦即为某些专门目的保留部分特殊字符。URI文法同时也就各种原因对协议内容加以其他的限制,例如,保证各种分层协议之间的协同性。百分号编码也为URI提供附加信息。

Intent中的Data数据域:

Each <data> element can specify a URI and a data type (MIME media type). There are separate attributes — schemehostport, and path — for each part of the URI:

scheme://host:port/path

For example, in the following URI,

content://com.example.project:200/folder/subfolder/etc

the scheme is "content", the host is "com.example.project", the port is "200", and the path is "folder/subfolder/etc". The host and port together constitute the URI authority; if a host is not specified, the port is ignored.

Each of these attributes is optional, but they are not independent of each other: For an authority to be meaningful, a scheme must also be specified. For a path to be meaningful, both a scheme and an authority must be specified.

When the URI in an Intent object is compared to a URI specification in a filter, it's compared only to the parts of the URI actually mentioned in the filter只比较filter中含有的部分. For example, if a filter specifies only a scheme, all URIs with that scheme match the filter. If a filter specifies a scheme and an authority but no path, all URIs with the same scheme and authority match, regardless of their paths. If a filter specifies a scheme, an authority, and a path, only URIs with the same scheme, authority, and path match. However, a path specification in the filter can contain wildcards to require only a partial match of the path.

The type attribute of a <data> element specifies the MIME type of the data. It's more common in filters than a URI. Both the Intent object and the filter can use a "*" wildcard通配符 for the subtype field — for example, "text/*" or "audio/*" — indicating any subtype matches.

The data test compares both the URI and the data type in the Intent object to a URI and data type specified in the filter. The rules are as follows:

a.       An Intent object that contains neither a URI nor a data type passes the test only if the filter likewise does not specify any URIs or data types.

b.      An Intent object that contains a URI but no data type (and a type cannot be inferred from the URI) passes the test only if its URI matches a URI in the filter and the filter likewise does not specify a type. This will be the case only for URIs like mailto: and tel: that do not refer to actual data.

c.       An Intent object that contains a data type but not a URI passes the test only if the filter lists the same data type and similarly does not specify a URI.

d.      An Intent object that contains both a URI and a data type (or a data type can be inferred from the URI) passes the data type part of the test only if its type matches a type listed in the filter. It passes the URI part of the test either if its URI matches a URI in the filter or if it has acontent: or file: URI and the filter does not specify a URI. In other words, a component is presumed to support content: and file: data if its filter lists only a data type.

If an intent can pass through the filters of more than one activity or service, the user may be asked which component to activate. An exception is raised if no target can be found.

 

在计算机网络领域,a URI scheme(URI模式) is the top level of the Uniform Resource Identifier(URI) naming structure。所有的URIs和全部的URI引用都是由一个scheme name,后面跟着一个冒号,然后剩下的部分称为scheme-specific part(特定模式组成部分,即不同的模式下,组成不相同的部分)

URI模式有时被错误的称为“协议”,或者称为URI协议或者URL协议,因为大多数模式最初设计时都使用一个特定的协议,并且通常也采用与协议相同的名字。例如,http模式通常用来使用超文本传输协议与Web资源进行交互。

URI模式需要向IANA进行注册,然而非注册的模式在实际中也有使用。

RFC3986 或者称为Internet standard STD66 定义了在所有URI模式中都使用的通用语法,每一个URI被定义为由四部分组成:

<scheme name> : <hierarchical part> [ ? <query> ] [ # <fragment> ]

模式名称consists of a letter followed by any combination of letters, digits, and the plus ("+"), period ("."), or hyphen ("-") characters,它的后面跟着一个冒号。

URIhierarchical part is intended to hold identification information hierarchical in nature. Usually this part begins with a double forward slash ("//"), followed by an authority part and an optional path.

  • The authority part holds an optional user information part terminated with "@" (e.g. username:password@), a hostname (i.e. domain name or IP address), and an optional port number preceded by a colon ":".
  • The path part is a sequence of segments (conceptually similar to directories, though not necessarily representing them) separated by a forward slash ("/"). Each segment can contain parameters separated from it using a semicolon (";"), though this is rarely used in practice.

·         The query is an optional part separated with a question mark, which contains additional identification information which is not hierarchical in nature. The query string syntax is not generically defined, but is commonly organized as a sequence of <key>=<value> pairs separated by a semicolon[1][2][3] or separated by an ampersand, for example:

·         Semicolon: key1=value1;key2=value2;key3=value3

·         Ampersand: key1=value1&key2=value2&key3=value3

·         The fragment is an optional part separated from the front parts by a hash ("#"). It holds additional identifying information that provides direction to a secondary resource, e.g. a section heading in an article identified by the remainder of the URI. When the primary resource is an HTML document, the fragment is often an id attribute of a specific element and web browsers will make sure this element is visible.

 

Official IANA-registered schemes列表位于:http://en.wikipedia.org/wiki/URI_scheme

原创粉丝点击