🔗 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)中使用
- 計算結果僅供參考,請以實際應用場景為準