CodeToolProCodeToolPro
GitHub

URL Encoder / Decoder

Decoded

  • Encoded

  • 技术详情

    URL 编码/解码器的工作原理

    工具功能

    URL 编码/解码器可将普通文本与百分号编码(又称 URL 编码)格式互相转换。URL 编码将非 ASCII 字符和 URL 中的保留字符转换为 %XX 格式(如空格→%20,中文→%E4%B8%AD)。该工具支持双向转换:编码(encodeURIComponent 模式)和解码。解码时自动识别 UTF-8 编码,正确处理中文、日文等多字节字符。


    常见开发者使用场景

    URL 编码是 Web 开发的必备技能。在构建 API 请求的 query string 时,需要对参数值进行编码以确保特殊字符(&、=、# 等)不被误解析。在前端传递 URL 中包含中文参数的搜索词时,需要先编码再发送。在解析第三方回调 URL 中的参数时,需要先解码才能读取原始内容。

    编码后的数据可以配合 Base64 编码器 在不同层级处理,或者使用 URL 解析器 分析完整 URL 的各个部分。


    编码差异:encodeURI vs encodeURIComponent

    URL 编码有两个常见函数,行为不同:encodeURI 保留 URL 语法字符(://、?、&、# 等),适合编码完整 URL 中的非法字符;encodeURIComponent 编码除字母数字外的所有字符,适合编码单个参数值。该工具默认使用 encodeURIComponent 模式(更安全、更通用),确保所有特殊字符都被正确编码。


    常见陷阱与注意事项

    • 双重编码:已编码的字符串再次编码会导致 % 变成 %25,使原始数据无法恢复。解码前确认字符串是否已经编码。
    • 字符编码:URL 编码基于 UTF-8 字节表示,不同字符编码会导致不同结果。该工具使用 UTF-8。
    • 加号与空格:在 application/x-www-form-urlencoded 格式中,空格被编码为 + 而非 %20,该差异在解析表单数据时需注意。
    • 保留字符:问号、等号、井号等在 URL 中有特殊含义,作为参数值时必须编码。

    何时使用此工具而非代码

    在快速调试 API 请求、构建测试 URL、或检查 URL 参数时使用此工具。对于生产代码,推荐使用 JavaScript 内置的 encodeURIComponent/decodeURIComponent 函数或编程语言的标准 URL 库,它们能更好地与网络请求框架集成。

    How to Use URL Encoder / Decoder

    1. 1Enter your text or data into the input field
    2. 2Select the encoding or decoding direction
    3. 3View the encoded or decoded result instantly
    4. 4Copy the output for use in your application

    Frequently Asked Questions

    • Is the encoding/decoding process reversible?

      Yes. All encoding formats supported here are lossless and fully reversible. Decode back to the original data at any time with 100% fidelity.

    • Is URL Encoder / Decoder free?

      Yes, 100% free. No registration, no credit card required. All tools are freely available for developers worldwide.

    • Does this tool upload my data to any server?

      No. All processing runs locally in your browser using client-side JavaScript. Your input data, code, or files never leave your device. We do not store, log, or transmit any user data.