Toolypet
开发工具/URL编码器/解码器

URL编码器/解码器

编码或解码URL组件和查询字符串

输入

输出

结果将显示在这里...

选项

URL Encoding Guide

Learn how to encode and decode URLs properly

What is URL Encoding?

URL encoding converts characters into a format that can be safely transmitted over the Internet. Special characters like spaces, &, ?, and = are converted to percent-encoded values (e.g., space becomes %20).

How to Use This Tool

  1. Enter a URL or text containing special characters
  2. Choose between full URL encoding or component encoding
  3. Click 'Encode' or 'Decode' as needed
  4. Copy the result using the copy button

Pro Tips

  • Use 'Encode Component' for query parameter values only
  • Full URL encoding preserves the URL structure (://, /, etc.)
  • Always encode user input before adding it to URLs to prevent injection

Browser Support

URL encoding uses the standard encodeURIComponent() and encodeURI() functions available in all modern browsers.

常见问题

为什么需要URL编码?

URL只能包含特定的ASCII字符。特殊字符(空格、中文、&、=等)必须编码为%XX格式才能安全传输。否则可能破坏URL结构或导致服务器解析错误。例如空格编码为%20或+。

encodeURI和encodeURIComponent有什么区别?

encodeURI()编码完整URL,保留:、/、?、#等URL结构字符。encodeURIComponent()编码URL组件(如查询参数值),会编码所有特殊字符。处理参数值时应使用encodeURIComponent()。

空格编码为%20还是+?

在URL路径中,空格应编码为%20。在application/x-www-form-urlencoded格式(表单提交)中,空格编码为+。encodeURIComponent()使用%20,URLSearchParams使用+。两种方式服务器通常都能正确解析。

哪些字符需要URL编码?

以下字符需要编码:空格、中日韩等非ASCII字符、特殊符号(!、@、#、$、%、^、&、*等)、保留字符(?、=、&用在非用途场合时)。字母、数字、-、_、.、~通常不需要编码。

双重编码是什么问题?

双重编码是对已编码的URL再次编码,例如%20变成%2520。这会导致服务器解码后得到错误结果。处理URL时要注意判断是否已经编码,避免重复编码。常见于多次字符串拼接场景。