美文网首页
(二)HTTP URI

(二)HTTP URI

作者: 捞小虾 | 来源:发表于2018-03-29 14:19 被阅读14次

Author: Xu FC

URL


scheme:[//[user[:password]@]host[:port]][[/path][;params]][?query][#fragment]
  • URL 组件
    • Scheme: scheme:协议缩写的小写,比如 http/ftp 等。
    • Authority 部分:[//[user[:password]@]host[:port]]
      • User:password@: 用户名密码,比如 ftp://test:password@example.com,HTTP URL 不支持该部分。
      • Host:域名或者 IP 地址,如果是 IP 地址,IPv4 以十进制点分发表示, IPv6 必须包含在 [ ] 内。
      • Port:与 host 以 冒号(:)隔开,比如 http://[2018:5::17]:8080
    • Path 部分:[[/path][;params]] 服务器上的资源路径
      • Path: 一些 Web 框架中 path 是获取资源的物理路径,比如 /example/test.html 是指 Web 服务根目录下的 example 文件夹中的 test.html 文件;一些 Web 架构中 path 被抽象处理,并不是获取资源的物理路径,比如django 等。
      • Params:Path 参数,与 path 以分号(;)分隔,常见于 java 应用,有两种格式的 path 参数:
        • http://example.com/path;key=value
        • http://example.com/path;/path1/path2
    • Query: 以 ? 与 path 部分分隔, query 与 query 之间以 & 或 ; 分隔,query 结构为 name = value。
    • Fragment:资源的片段标志,以 # 开头,浏览器根据该标志位置显示资源。

HTTP URI


http-URI = "http:" "//" authority path-abempty [ "?" query ][ "#" fragment ]
  • Scheme: http: 或者 https:
  • Authority: //host:port
  • Path: /path/to/myfile;params
  • Query: ?queries
  • Fragment: #somewhere_in_the_document

示例:

http://example.com/path/to/myfile.html?key1=value1&key2=value2#chapter1
https://192.168.1.100:8080/path;id=1234567890
http://[2018:5::17]:8080/mypath;/path/to
  • Request-target
request-target = origin-form
                    / absolute-form
                    / authority-form
                    / asterisk-form
  • Origin-form
origin-form    = absolute-path [ "?" query ]

示例: http://www.test.com/path?query=value

GET /path?query=value HTTP/1.1
Host: www.test.com

URI 不能为空,如果请求为 http://www.test.com,请求的 URI 为 / ,即:

GET / HTTP/1.1
Host: www.test.com

  • Absolute-form
absolute-form  = absolute-URI

示例:http://www.test.com/path?query=value

GET http://www.test.com/path?query=value HTTP/1.1
Host: www.test.com

  • Authority-form
authority-form = authority

示例:

CONNECT www.test.com:80 HTTP/1.1
Host: www.test.com:80

  • Asterisk-form
asterisk-form = "*"

型号 URI 只支持 OPTIONS method, 表示请求服务器支持的 methods。

root@ads_test_client_1:/home/test/test_scripts# telnet 192.168.1.100 80
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
OPTIONS * HTTP/1.1
Host: 192.168.1.100


P.S.

一些厂家并不严格遵守RFC规范,设计出各种各样的URL,比如以下为微软产品支持的URL:

微软的报表服务器:
http://myrshost/reportserver?/Sales/YearlySalesByCategory&rs:Command=Render
微软的SharePoint:
http://myspsite/subsite/_vti_bin/reportserver?http://myspsite/subsite/Sales/YearlySalesByCategory&rs:Command=Render

相关文章

网友评论

      本文标题:(二)HTTP URI

      本文链接:https://www.haomeiwen.com/subject/alrucftx.html