URL编码器和解码器 - 查询字符串编码 在线
即时编码或解码URL、查询参数和特殊字符。解析URL组件并在编码和解码格式间转换。
编码类型
空格
解码
输入
输出
常见问题
什么是URL编码?
URL编码(也称为百分号编码)将字符转换为可以在URL中安全传输的格式。在URL中具有特殊含义或不允许的字符(如空格、&、?、=)被替换为百分号后跟其十六进制值。例如,空格变成%20,@变成%40。
什么时候应该使用URL编码?
在以下情况使用URL编码:将用户输入作为URL查询参数传递时,在URL路径中包含特殊字符时,通过GET请求提交表单数据时,使用动态值创建API请求URL时,或在URL中编码非ASCII字符(如中文或表情符号)时。它确保您的URL有效并被浏览器和服务器正确解析。
encodeURIComponent和encodeURI有什么区别?
encodeURIComponent编码除A-Z、a-z、0-9和- _ . ! ~ * ' ( )之外的几乎所有字符。用于编码查询参数值。encodeURI保留URL结构字符如: / ? # @,用于编码完整URL同时保持其功能性。值使用encodeURIComponent,完整URL使用encodeURI。
空格应该编码为%20还是+?
两者都有效,但用于不同的场景。%20是URL中空格的标准RFC 3986编码。+号用于application/x-www-form-urlencoded格式(HTML表单提交)。现代Web API通常期望%20,而表单数据传统上使用+。此工具支持两种选项。
URL编码安全吗?
URL编码不是加密 - 它只是一种在URL中安全表示字符的方式。解码后您的数据仍然可读。此工具在您的浏览器中处理所有内容,因此您的数据永远不会离开您的设备。对于敏感数据,请始终使用HTTPS和适当的身份验证。
代码示例
// Encode query parameter value
const encoded = encodeURIComponent('hello world & more');
console.log(encoded); // "hello%20world%20%26%20more"
// Decode
const decoded = decodeURIComponent(encoded);
console.log(decoded); // "hello world & more"
// Encode full URL (preserves structure)
const url = encodeURI('https://example.com/path?q=hello world');
console.log(url); // "https://example.com/path?q=hello%20world"