我一直在阅读,似乎没有很好的连贯和完全接受的URL部分术语。真的吗?我想知道URL部分术语存在哪些标准。什么是最常见的?有没有完善的标准?
我找到了以下内容:
foo://example.com:8042/over/there?name=ferret#nose
\_/ \______________/\_________/ \_________/ \__/
| | | | |
scheme authority path query fragment
| _____________________|__
/ \ / \
urn:example:animal:ferret:nose
window.location
protocol://username:password@hostname:port/pathname?search#hash
-----------------------------href------------------------------
-----host----
----------- origin -------------
protocol
- URL的协议方案,包括最终的':'hostname
- 域名port
- 港口号码pathname
- / pathnamesearch
- ?参数hash
- #fragment_identifierusername
- 在域名之前指定的用户名password
- 在域名之前指定的密码href
- 整个网址origin
- protocol:// hostname:porthost
- 主机名:端口url
在带有URL的行上方,您可以看到节点的url
模块旧API,而在该行下您会看到新的API。似乎节点从RFC标准术语转移到更加浏览器友好的标准术语,即类似于浏览器的windows.location
。
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ href │
├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤
│ protocol │ │ auth │ host │ path │ hash │
│ │ │ ├─────────────────┬──────┼──────────┬────────────────┤ │
│ │ │ │ hostname │ port │ pathname │ search │ │
│ │ │ │ │ │ ├─┬──────────────┤ │
│ │ │ │ │ │ │ │ query │ │
" https: // user : pass @ sub.example.com : 8080 /p/a/t/h ? query=string #hash "
│ │ │ │ │ hostname │ port │ │ │ │
│ │ │ │ ├─────────────────┴──────┤ │ │ │
│ protocol │ │ username │ password │ host │ │ │ │
├──────────┴──┼──────────┴──────────┼────────────────────────┤ │ │ │
│ origin │ │ origin │ pathname │ search │ hash │
├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤
│ href │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
URL: http://video.google.co.uk:80/videoplay?docid=-7246927612831078230&hl=en#00h02m30s
我的一些担忧:
window.location
是标准还是基于标准?http://
称为protocol
或scheme
吗?host
或authority
?window.location
和节点都没有TLD或其他域部分的属性?hostname
(example.com)和host
(example.com:8080)之间的术语差异已经确立?origin
不包括username:password@
,而对于windows.location
它确实我想在我的代码上遵循完善的标准或最佳实践。
Java java.net.URL遵循RFC 2396,它是RFC 3986的旧版本。
Python的urlparse也遵循RFC 3986,除了使用netloc
而不是authority
可能由于遗留原因。
换句话说,我会遵循RFC 3986。