URL 編碼
高亮为百分号编码字节。
免費線上 URL 編碼解碼工具,支援 encodeURIComponent/encodeURI/RFC 3986 等模式,編碼高亮,批量模式,Query Only 模式。瀏覽器本機處理。
相關推薦
什麼是 URL 編碼?
URL 編碼(百分號編碼)將 URL 中非安全字元轉換為 %XX 格式,URL 只能使用 ASCII 字母數字和 -_.~,其他字元(中文、空格、符號)必須編碼。
encodeURIComponent 編碼最徹底(含 &、=、?),適合參數值;encodeURI 保留 URL 結構字元,適合完整 URL。
RFC 3986 將波浪號 ~ 視為安全字元不編碼,是目前推薦標準。
Query Only 模式只編碼參數值,保留鍵名和符號。
所有計算在瀏覽器本機完成,資料不上傳。
適用場景
- API debugging: compare encodeURIComponent vs encodeURI outputs to debug signature mismatches
- Log decoding: batch-decode URL-encoded log entries back to readable text
- URL building: Query Only mode preserves keys while encoding values
- Frontend dev: encoding highlight helps understand which characters get escaped
- Data migration: batch process URL-encoded data from legacy systems
使用方法
- Paste URL or text to encode/decode
- Select direction (Encode/Decode) and mode (Component/URI/full/RFC 3986)
- Enable batch mode for multi-line, or Query Only for parameter values only
- Copy the highlighted result for API requests or URL building
功能特點
- 四种编码模式:encodeURIComponent / encodeURI / full / RFC 3986 一键切换,实时对比不同规则输出差异
- 编码高亮:实时高亮显示被转义的 %XX 字符,琥珀色标记让编码结果一目了然
- 批量模式:支持多行批量编码解码,每行独立处理,适合处理日志或批量数据
- Query Only 模式:只编码 URL 参数值部分(等号后内容),保留键名、符号和路径结构不变
- 实时防抖:300ms 自动编码解码,无需点击按钮,输入即出结果
- 字符统计:实时显示输入字符数,方便核对 API 参数长度限制
程式碼範例
URL Encoding/Decoding in JavaScript
// encodeURIComponent: encodes individual param values (most common)
const param = encodeURIComponent('Zhang San&Li Si');
console.log(param);
// encodeURI: encodes full URL (preserves :/?#&= structural chars)
const url = encodeURI('https://example.com/search?q=hello world');
console.log(url);
// Decode
const decoded = decodeURIComponent(param);
console.log(decoded);
// RFC 3986 compliant (~ not encoded)
function rfc3986Encode(str) {
return encodeURIComponent(str).replace(/[!'()*]/g,
c => '%' + c.charCodeAt(0).toString(16).toUpperCase());
}
// Modern: URLSearchParams (auto-handles encoding)
const params = new URLSearchParams({name:'Zhang San',city:'Beijing'});
console.log(params.toString());URL Encoding/Decoding in Python
from urllib.parse import quote, unquote, urlencode, quote_plus
# quote: similar to encodeURIComponent
encoded = quote('Zhang San&Li Si')
print(encoded)
# RFC 3986 is default (~ not encoded)
print(quote('hello~world')) # hello~world
# quote_plus: spaces become + (form format)
print(quote_plus('hello world')) # hello+world
# Decode
print(unquote(encoded))
# urlencode: build query strings
params = urlencode({'name':'Zhang San','city':'Beijing'})
print(params)URL Encoding/Decoding in Java
import java.net.URLEncoder;
import java.net.URLDecoder;
import java.net.URI;
import java.nio.charset.StandardCharsets;
public class URLEncodeExample {
public static void main(String[] args) throws Exception {
String encoded = URLEncoder.encode("Zhang San&Li Si", "UTF-8");
System.out.println(encoded);
String decoded = URLDecoder.decode(encoded, "UTF-8");
System.out.println(decoded);
URI uri = new URI("https","example.com","/search","q=hello",null);
System.out.println(uri.toASCIIString());
}
}常見問題
encodeURIComponent vs encodeURI?
encodeURIComponent encodes all non-safe characters including &, =, ? — suitable for individual parameter values. encodeURI preserves URL structural characters (: / ? #) — suitable for encoding complete URLs.
RFC 3986 vs standard encoding?
RFC 3986 treats tilde ~ as a safe unreserved character (not encoded), while older standards encode it as %7E. RFC 3986 reduces unnecessary escapes and improves URL readability.
When to use Query Only mode?
When you have a query string like ?name=张三&city=北京 and only want parameter values encoded, leaving keys and symbols intact. Output: ?name=%E5%BC%A0%E4%B8%89&city=%E5%8C%97%E4%BA%AC.
Should spaces be + or %20?
In application/x-www-form-urlencoded (HTML forms), spaces become +. In URL paths and encodeURIComponent, spaces always become %20. This tool uses %20 by default.
Why do different tools produce different results for Chinese?
It depends on character encoding. This tool uses UTF-8 (the Web standard). If another tool uses GBK, results will differ. Always use UTF-8 for Web URLs.
What does encoding highlight do?
Highlights %XX-encoded characters in amber, helping you understand encoding rules: letters/digits are safe and not encoded, while Chinese and special symbols are.
Does % itself need encoding?
Yes. % is the escape character — if a literal % appears in a parameter value, it must be encoded as %25, otherwise it will be misinterpreted as an encoded byte.
術語表
- Percent-encoding
- The formal name for URL encoding, representing characters as % followed by two hex digits. Space→%20, 中→%E4%B8%AD.Wikipedia
- encodeURIComponent
- JavaScript built-in encoding all chars except A-Z a-z 0-9 - _ . ! ~ * ' ( ). Used for individual query parameter values.
- encodeURI
- JavaScript built-in preserving URL structural characters (: / ? # [ ] @ ! $ & ' ( ) * + , ; =), used for encoding complete URLs.
- RFC 3986
- The current IETF URI standard (2005) defining URL encoding rules, classifying ~ as unreserved. Replaces RFC 2396/1738.RFC 3986
- Reserved Characters
- Characters with special meaning in URLs (: / ? # [ ] @ ! $ & etc.) that must be encoded when used as data but not in their structural roles.
- Unreserved Characters
- Characters safe anywhere in URLs without encoding: A-Z, a-z, 0-9, -, _, ., ~ (per RFC 3986).
- Query String
- The part of a URL after ?, consisting of key=value pairs separated by &.
- URLSearchParams
- Modern browser API for safely building/parsing query strings with automatic encoding.
- application/x-www-form-urlencoded
- HTML form submission format where spaces become + instead of %20. Server frameworks usually handle both.
- UTF-8 Encoding
- The Web standard. Non-ASCII characters (Chinese, emoji) are first converted to UTF-8 byte sequences, then each byte is %XX-encoded.
Character Encoding Comparison Across 4 Modes
| Character | Description | encodeURIComponent | encodeURI | RFC 3986 |
|---|---|---|---|---|
space | Space | %20 | %20 | %20 |
! | Exclamation | %21 | ! | %21 |
# | Fragment | %23 | # | %23 |
& | Param separator | %26 | & | %26 |
' | Single quote | %27 | ' | %27 |
( | Left paren | %28 | ( | %28 |
) | Right paren | %29 | ) | %29 |
* | Asterisk | %2A | * | %2A |
+ | Plus | %2B | + | %2B |
/ | Path separator | %2F | / | %2F |
: | Colon | %3A | : | %3A |
; | Semicolon | %3B | ; | %3B |
= | Equals | %3D | = | %3D |
? | Query string | %3F | ? | %3F |
@ | At sign | %40 | @ | %40 |
~ | Tilde | %7E | %7E | ~ |
Common URL Reserved Characters Quick Reference
| Encoded | Char | URL Purpose |
|---|---|---|
%20 | (space) | Space |
%23 | # | Fragment identifier (hash) |
%25 | % | Escape character itself |
%26 | & | Query parameter separator |
%2B | + | Plus / form space |
%2F | / | Path separator |
%3A | : | Scheme separator |
%3D | = | Key-value separator |
%3F | ? | Query string start |
%40 | @ | Auth/email separator |
Authoritative References
- 安全字串比較
- 二進位轉換
- 凱薩密碼
- 摩斯密碼
- 十六進位轉換
- 影片轉 Base64
- Base64 轉影片
- 圖片轉 Base64
- Base64 轉圖片
- 文字轉 Base64
- Base64 轉文字
- 檔案雜湊校驗
- 檔案轉 Base64
- Base64 轉檔案
- 音訊轉Base64
- Base64轉音訊
- AES 加密解密
- DES 加密解密
- Base32 編碼解碼
- Base58 編碼解碼
- Base64 編碼
- Base64 解碼
- Base64 比較
- Base64 拆分
- Base64 多行合併
- Base64 格式化
- Base64 格式檢查
- Base64 批次編碼
- Base64 批次解碼
- Base64 清理
- Base64 填充處理
- Base64 長度統計
- Base64 轉十六進位
- Base64 DataURL 轉換
- Base64-Hex 互轉
- Base85 編解碼器
- HMAC 生成與驗證
- PBKDF2 金鑰派生
- MD5 雜湊
- SHA-256 雜湊
- SHA1 雜湊
- SHA512 雜湊
- JWT 工具
- HTML 實體編碼解碼
- Unicode 跳脫
- URL 編碼
- URL Safe Base64
- MIME Base64
- Java 混淆
- JS 混淆
- PHP 混淆
- Python 混淆