🔗 URLParser
📐 工作原理与说明
用 new URL(输入) 解析,取出 href、protocol、hostname、port、host、pathname、search、hash、origin、username、password 等字段,并用 searchParams.getAll 把查询串展开为「参数名 → 值数组」的映射(重复键逐行保留),所有字段值经 HTML 文本转义后再渲染。字段为空时显示「(空)」,参数表逐行渲染为可复制的键值行;输入为空时提示输入 URL,构造失败时给出错误提示
拆解 URL 的各个组成部分。
- 结构:
scheme://host:port/path?query#fragment。 - 组成:协议、主机名、端口、路径、查询串与片段标识。
- 端口:可省略,按协议取默认值(http 为 80、https 为 443)。
- 用途:提取域名与路径、校验 URL 合法性、分析链接结构。
Parse any URL into scheme, host, path, query and fragment in your browser, and inspect or edit each component.
默认保存脱敏记录:移除用户名/密码,token、secret、signature 等敏感参数值替换为 ***;勾选上方选项才会在本机保存完整地址。
查询参数
构建结果
-
📋 URL结构说明
protocol://username:password@hostname:port/pathname?search#hash
| 部分 | 说明 | 示例 |
|---|---|---|
| protocol | 协议,访问资源的方式 | https:, http:, ftp: |
| hostname | 主机名/域名 | www.example.com |
| port | 端口号(可选) | 8080, 443 |
| pathname | 路径,资源位置 | /path/to/page |
| search | 查询字符串,?开头 | ?key=value&foo=bar |
| hash | 片段标识符,#开头 | #section |
| username/password | 认证信息(少用) | user:pass@ |
🌐 常见端口号
| 端口 | 协议 | 用途 |
|---|---|---|
| 21 | FTP | 文件传输 |
| 22 | SSH | 安全远程登录 |
| 80 | HTTP | 超文本传输(默认) |
| 443 | HTTPS | 加密HTTP(默认) |
| 3306 | MySQL | MySQL数据库 |
| 5432 | PostgreSQL | PostgreSQL数据库 |
| 6379 | Redis | Redis缓存 |
| 8080 | HTTP-ALT | HTTP备用/开发 |
| 27017 | MongoDB | MongoDB数据库 |
📝 URL示例
https://www.google.com/search?q=hello+world&hl=zh-CN
https://github.com/user/repo/pull/123#issuecomment-456
http://localhost:3000/api/users?id=1&format=json
https://www.bilibili.com/video/BV1xx411c7mD?p=5&t=120
https://zh.wikipedia.org/wiki/URL#语法
📜 解析历史
📚 深度解析:URL 解析器
💡 常见使用场景
- 拆出协议、主机、路径、查询、锚点。
- 核对重定向规则:把 URL 拆开看清协议、主机、端口、路径与查询,确认规则匹配的是哪一部分。
解析
`https://ex.com:8080/p?a=1&b=2#top` → protocol=https, host=ex.com:8080, port=8080, path=/p, query=a=1&b=2, hash=top。
❓ 常见问题(FAQ)
- 默认端口要显示吗?
- 浏览器 URL API 会把 http:80、https:443 这类默认端口规范化为空,结构化的端口字段常显示为空;非默认端口(如 8080、8443)原样保留,完整 href 仍保留你输入的形态。
- 为什么解析不出查询参数?
- 常见原因:查询串里有未编码的 #(会被当作片段标识符,其后内容不属于查询)、多个 ? 导致切分错误,或参数值里含 & 却未编码。另外相对 URL 需先基于一个基准 URL 解析,直接解析会缺少协议与主机部分。
Formula & Standard References
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Components | scheme://userinfo@host:port/path?query#fragment | RFC 3986 Section 3 |
| Percent encoding | encode others as %HH; space as %20 or plus in forms | RFC 3986 Section 2.1 |
| Case rules | scheme and host are case-insensitive; path and query are not | RFC 3986 Section 6.2.2.1 |
⚠️ 使用说明与注意事项
- 本工具纯前端运行,数据不会上传到服务器
- 建议在主流浏览器(Chrome/Safari/Firefox/Edge)中使用
- 计算结果仅供参考,请以实际应用场景为准