URI的基本格式以及与URL的区别

  • 当没有URI时:
      • 站长欲分享一部电影给Forrest Gump给B时,需要告诉:
      • 请使用FTP协议访问mysite.net,端口是8502
      • 登陆用户名是user,密码是pass
      • 进入到/shared/movie/目录下
      • 转换为二进制格式
      • 下载名字为Forrest Gump.mkv格式的文件
  • 有了URIftp://user:pass@mysite.net:8502/shared/movie/Forrest Gump.mkv(我们管这种方式也可以叫URL)

URL:RFC1738(1994.12),Uniform Resource Locator ,表示资源的位置,期望找到提供查找资源的方法。

URN: RFC2141(1997.5),Uniform Resource Name ,期望为资源提供持久的的,与位置无关的的表示方式,并允许简单的将多个命名空间映射到单个URN命名空间。

  • 例如磁力链接:magnet:?xt=urn:sha1:YNCKHTQC5C

URI:RFC1630(1994.6)、RFC3986(2005.1,取代RFC2396和RFC2732),Uniform Resource Identifier,用以区分资源,是URL和URN的超集,用以取代URL和URN概念

Uniform Resource Identifier 统一资源标识符

Resource资源

  • 可以是图片、文档、今天上海的天气温度,也可以是不能通过互联网访问的实体
  • 一个资源可以有多个URI

Identifier 标识符

  • 将当前资源与其他资源区分开的名称

Uniform 统一

  • 允许不同种类的资源在同一上下文中出现
  • 对不同种类资源标识符可以使用同一语义进行解读
  • 引入新标识符时,不会对已有标识符产生影响
  • 允许同一资源标识符在不同的、Internet规模下的上下文中出现

合法的URI:

  • ftp://ftp.is.co.za/rfc/rfc1808.txt
  • http://www.ietf.org/rfc/rfc2396.txt
  • ldap://[2001:db8::7]/c=GB?objectClass?one
  • mailto:John.Doe@example.com
  • news:comp.infosystems.www.servers.unix
  • telnet://192.0.2.16:80/
  • urn:oasis:names:specification:docbook:dtd:xml:4.1.2


URI格式

  • URI = scheme ":" hire-part ["?" query] [ "#" fragment ]
  • scheme = ALPHA * (ALPHA / DIGIT / "+" / "-" / "." ) 
      • 例如 http,https,ftp,mailto,rtsp,file,telnet
  • query = *( pchar / "/" / "?" )
  • fragment = * ( pchar / "/" / "?"  )

 示例: https://tools.ietf.org/html/rfc/7231?test=1#page-7

 hire-part = "//" authority path-abempty / path-absolute / path-rootless / path-empty 

  • authority = [ userinfo "@" ] host [ ":" port]
  • userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
  • host = IP-literal / IPv4adress / reg-name
  • port = *DIGIT

  实例:https://tom:pass@localhost:8080/index.html

 path = path-abempty / path-absolute / path-noscheme / path-rootless / path-empty

  • path-abempty = *( "/" segment) 以/开头的路径或者空路径
  • path-absolute = "/" [ segment-nz *( "/" segment )] 以/开头的路径,但是不能以//开头
  • path-noscheme  = segment-nz-nc *( "/" segment )以非:开头的路径
  • path-rootless = segment-nz *( "/" segment )相对path-noscheme,增加允许以:开头的路径
  • path-empty = 0 < pchar > 空路径

 向正向代理发出的请求中,传递的绝对URI。

posted @ 2019-05-26 17:09  冯小圆  阅读(7818)  评论(0编辑  收藏  举报