Skip to content
URL 编码 / 解码
Tools

URL 编码 / 解码

对文本进行百分号编解码并解析查询字符串,全程在浏览器中完成。

Special characters reference
Character Encoded (%XX) Notes
space %20 Also encoded as + in HTML form query strings
& %26 Query param separator — encode in values
= %3D Key-value separator in query strings
? %3F Marks the start of a query string
# %23 Fragment identifier
/ %2F Path separator
: %3A Protocol / port separator
@ %40 Username delimiter in URLs
+ %2B Literal plus sign (+ in query string = space)
% %25 Percent itself — encode to avoid ambiguity
%E2%82%AC UTF-8 multi-byte (3 bytes)
© %C2%A9 UTF-8 multi-byte (2 bytes)
Per-language code snippets

Copy-ready snippets for JavaScript, Python, C#, PowerShell, Java and Go.

JavaScript / Node.js
// Encode a single query value (recommended)
const encoded = encodeURIComponent('hello world & co.');
// → 'hello%20world%20%26%20co.'

// Decode
const decoded = decodeURIComponent('hello%20world%20%26%20co.');
// → 'hello world & co.'

// Encode a full URL (leaves : / ? & # intact)
const safeUrl = encodeURI('https://example.com/search?q=hello world');
// → 'https://example.com/search?q=hello%20world'
Python
from urllib.parse import quote, unquote, urlencode

# Encode a single value (%20 for spaces)
encoded = quote('hello world & co.')
# → 'hello%20world%20%26%20co.'

# Decode
decoded = unquote('hello%20world%20%26%20co.')
# → 'hello world & co.'

# Encode a query dict (uses + for spaces — form encoding)
qs = urlencode({'q': 'hello world', 'page': '2'})
# → 'q=hello+world&page=2'

# quote_plus encodes spaces as + (match HTML form encoding)
plus = quote_plus('hello world')
# → 'hello+world'
C# / .NET
// Encode a single value (spaces → %20)
string encoded = Uri.EscapeDataString("hello world & co.");
// → "hello%20world%20%26%20co."

// Decode
string decoded = Uri.UnescapeDataString("hello%20world%20%26%20co.");
// → "hello world & co."

// Older System.Web API (spaces → +, form encoding):
// HttpUtility.UrlEncode("hello world") → "hello+world"
PowerShell
# .NET method — works in PS 5+ and PowerShell Core
$encoded = [Uri]::EscapeDataString('hello world & co.')
# → 'hello%20world%20%26%20co.'

$decoded = [Uri]::UnescapeDataString('hello%20world%20%26%20co.')
# → 'hello world & co.'

# Alternate via System.Web (Desktop PS only):
Add-Type -AssemblyName System.Web
$enc2 = [System.Web.HttpUtility]::UrlEncode('hello world')
# → 'hello+world'
Java
import java.net.URLEncoder;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;

// Encode (URLEncoder uses + for spaces — form encoding)
String encoded = URLEncoder.encode("hello world & co.", StandardCharsets.UTF_8);
// → "hello+world+%26+co."

// Decode
String decoded = URLDecoder.decode("hello+world+%26+co.", StandardCharsets.UTF_8);
// → "hello world & co."
Go
import "net/url"

// QueryEscape: spaces become +
encoded := url.QueryEscape("hello world & co.")
// → "hello+world+%26+co."

decoded, err := url.QueryUnescape("hello+world+%26+co.")
// → "hello world & co.", nil

// PathEscape: spaces become %20
pathSafe := url.PathEscape("hello world & co.")
// → "hello%20world%20&%20co."

Runs entirely in your browser. Nothing is uploaded.

免费在线 URL 编码与解码工具

这款 URL 编码与解码工具可将文本转换为百分号编码格式——或还原该过程——直接在您的浏览器中完成。粘贴文本,选择编码或解码,选择组件完整 URI 规则,结果即时更新。无需上传任何内容;每项操作完全在您的浏览器中使用与您代码相同的内置 JavaScript 函数运行。

百分号编码在 Web 开发中不可避免。空格、与号、等号和非 ASCII 字符在能安全地出现在 URL 中之前都必须进行转义。无论您是在构建 API 请求、调试跟踪链接还是阅读服务器日志,此工具都能处理所有边界情况——包括多字节 UTF-8 字符、格式错误的序列以及 +%20 之间的空格歧义。

encodeURIComponent 与 encodeURI——该用哪个规则?

encodeURIComponent 适用于单个查询值、路径段或任何要插入 URL 的字符串。它会编码几乎所有特殊字符——包括 ?&=/#:——确保该值不会破坏 URL 结构。示例:'hello world & page=2' 变为 'hello%20world%20%26%20page%3D2'

encodeURI 用于在不破坏完整 URL 的前提下进行编码。它保留结构性字符(: / ? # &)以使 URL 保持可用,同时仍对空格和非 ASCII 字符进行编码。如有疑问,对于作为值插入的内容请优先使用组件规则——这是几乎所有 Web 框架中的安全默认值。

空格:%20 还是 +——表单编码的区别

URL 中有两种有效的空格编码方式。在 URL 路径? 之前的部分)中,RFC 3986 要求使用 %20。在 HTML 表单查询字符串中,旧版 application/x-www-form-urlencoded 格式历史上以 + 表示空格——浏览器通过 GET 提交表单时至今仍使用此方式。

两者都表示"空格",但只在各自的上下文中有效。URL 路径中的 + 是字面量加号;查询字符串中的 + 是空格。查询值中的字面量加号必须编码为 %2B,否则会被误读。解码模式的将 + 视为空格开关在运行 decodeURIComponent 之前先将 + 替换为空格,适用于处理表单编码输入。

与 CyberChef 及其他 URL 编码工具的比较

CyberChef(来自 GCHQ)功能强大,但围绕"配方"管道概念设计——您需要将多个操作串联起来。仅为 URL 编码或解码,您仍然需要搜索操作、将其拖入配方,然后处理输入。对于复杂的数据转换它很出色;但对于快速编码/解码来说显得繁琐。

urldecoder.org 等其他在线工具虽然简单,但会显示广告,每次操作都需要整页刷新,且不提供各语言的代码片段。本工具每次按键即时更新结果,支持组件和完整 URI 两种规则,包含常见编码字符参考表,并以 JavaScript、Python、C#、PowerShell、Java 和 Go 显示可直接复制的代码——全程无需上传任何内容。

特殊字符快速参考

Web 开发中最常编码的字符:空格 → %20(或查询字符串中的 +)、& → %26= → %3D? → %3F# → %23/ → %2F: → %3A@ → %40+ → %2B% → %25。多字节 UTF-8 字符展开为多个序列:€ → %E2%82%ACé → %C3%A9

永远不会被编码的字符是非保留字符集:字母 A–Z 和 a–z、数字 0–9 以及四个符号 - _ . ~。其他所有内容——包括每个非 ASCII 字符——在符合标准的 URL 中都必须进行百分号编码。

在 JavaScript、Python、C#、PowerShell 和 Java 中进行 URL 编码

每种主流语言都内置了相应函数。JavaScript / Node.js 中:encodeURIComponent(str)decodeURIComponent(str)——无需任何导入。Python 中:urllib.parse.quote(str)unquote(str);完整查询字符串使用 urlencode(dict)C# 中:System 命名空间下的 Uri.EscapeDataString(str)Uri.UnescapeDataString(str)PowerShell 中:[Uri]::EscapeDataString(str),PS 5+ 和 PowerShell Core 均可用。Java 中:URLEncoder.encode(str, StandardCharsets.UTF_8)

各语言代码片段面板包含 JavaScript、Python、C#、PowerShell、Java 和 Go 的可直接复制代码,让您立即将正确的调用加入项目——并附有各语言标准库中 +%20 空格行为的说明。

100% 私密——离线也可使用

每次编码和解码操作仅使用浏览器内置函数:encodeURIComponentdecodeURIComponentencodeURIdecodeURI。任何文本都不会发送到服务器、不会被存储或记录——包括您粘贴的 URL 中的域名。页面加载完成后,即使断网设备也能完美运行。将其加入书签,随时需要编码、解码或检查 URL 时使用。

Frequently asked questions

什么是 URL 编码?

URL 编码(也称百分号编码)将 URL 中不安全的字符转换为 % 符号后跟两位十六进制数字。例如,空格变为 %20,与号变为 %26,井号变为 %23。它确保每个 URL 在任何浏览器、HTTP 标头或服务器上都有效,不受字符集影响。

URL 编码中 %20 是什么意思?

%20 是空格字符的百分号编码表示。20 是 ASCII 32(空格)的十六进制值。因此 URL 'hello%20world' 解码回 'hello world'。在 HTML 表单查询字符串中,您有时会看到用 + 代替 %20 表示空格——两者在查询字符串中含义相同,但在 URL 路径中不同。

encodeURI 和 encodeURIComponent 有什么区别?

encodeURIComponent 用于单个查询值或路径段——它编码几乎所有内容,包括 : / ? # & =,确保值不会破坏 URL 结构。encodeURI 用于完整 URL——它保留 : / ? & # 等结构性字符不变,使 URL 保持可用。作为规则,始终对插入链接的单个值使用 encodeURIComponent。

如何在 JavaScript 中进行 URL 编码?

对单个值使用 encodeURIComponent():encodeURIComponent('hello world & co.') 返回 'hello%20world%20%26%20co.'。用 decodeURIComponent() 还原。对完整 URL 使用 encodeURI() / decodeURI()——它们跳过结构性字符。两者都内置于所有浏览器和 Node.js,无需导入。

中文字符如何进行 URL 编码?

非 ASCII 字符(包括中文、日文、emoji 等)通过 UTF-8 编码转换为多个 %XX 序列。例如,汉字"中"的 UTF-8 编码为三个字节,URL 编码后为 %E4%B8%AD。encodeURIComponent() 会自动处理这一转换,您只需传入原始字符串即可。

空格有时是 %20、有时是 +,为什么?

在 URL 路径(? 之前)中,根据 RFC 3986,空格必须为 %20。在查询字符串中,HTML 表单使用的旧版 application/x-www-form-urlencoded 格式历史上将空格编码为 + 以求简洁。两者都表示"空格",但只在各自上下文中有效——查询值中的字面量 + 必须编码为 %2B,否则会被误读为空格。

在线编码/解码安全吗?

是的——本工具完全在本地运行。每次操作都在您的浏览器中使用内置 JavaScript 函数执行。您的文本永远不会发送到任何服务器、不会被存储或记录。页面加载后即使断网也能正常使用。这对于编码 API 密钥、凭据或令牌时尤为重要。

Related tools

查看全部工具