1. 介绍
URL: Uniform Resource Locator 同意资源定位器,俗称网页地址
2. 格式
<scheme>://<user>:<password>@<host>:<port>/<path>;<params>?<query>#<frag>
- scheme: 协议,常见的有http,https,file,ftp等
- user: 用户
- password: 密码
- host: 主机
- port: 端口
- path: 路径
- params: 参数
- query: 查询的参数
- frag: 信息片段
平时我们遇到的URL只包括其中的部分字段,按需来定。
3. 例子
1. http(s) 案例
http://127.0.0.1:8080/user/index.html?name="juejin"&id=1
scheme: 采用http协议
host: 127.0.0.1
port: 8080
path: ser/index.html
query: ?name="juejin"&id=1
2. mongoDb协议
在使用MongoDB中,我们可以使用URL链接来连接数据库,格式如下:
mongodb://<user>:<password>@<host>:<port>/<path>?<query>
例如:
mongodb://admin:123456@localhost:27017/test
表示: 用户admin,密码123456,主机localhost,要连接的数据库是test
3. ftp协议
ftp://<user>:<password>@<host>:<port>/<path>
ftp://test:test123@127.0.0.1:21/profile
表示: 用户名密码test,test123,站点127.0.0.1:21,文件路径 /profile
此文简单的介绍了URL格式,以及常用的案例。如有不对的地方,请留言,我会及时更改。