🧰 工具大全 ToolHub

URL 编解码与解析URL Encode, Decode & Parse

URL 编码分两种:整条 URL 编码(encodeURI,保留 : / ? 等结构符号)和参数值编码(encodeURIComponent,全部特殊字符都编码)——选错就会出 bug,这里分开给。再往下还能把一条 URL 拆开看:协议、主机、端口、路径、每个查询参数,清清楚楚。URL encoding comes in two flavors: full-URL encoding (encodeURI, keeps structural characters like : / ?) and component encoding (encodeURIComponent, encodes everything) — picking the wrong one is a classic bug, so both are here. Below, any URL is broken down into protocol, host, port, path and every query parameter.

URL 解析URL parser

说明Notes

解码时 + 号会按查询参数的惯例转成空格(application/x-www-form-urlencoded 规则);如果你的 + 是字面加号,请注意区分。中文等非 ASCII 字符编码为 UTF-8 百分号编码,与浏览器地址栏行为一致。On decode, + is turned into a space following the query-string convention (application/x-www-form-urlencoded). Non-ASCII characters are percent-encoded as UTF-8, exactly as browsers do.