logo
GeekFormat

URL 編碼

编码规范
URL 输入
0 chars

免費線上 URL 編碼解碼工具,支援 encodeURIComponent/encodeURI/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

功能特點

  • 四种编码模式:encodeURIComponent / encodeURI / full / RFC 3986 一键切换,实时对比不同规则输出差异
  • 编码高亮:实时高亮显示被转义的 %XX 字符,琥珀色标记让编码结果一目了然
  • 批量模式:支持多行批量编码解码,每行独立处理,适合处理日志或批量数据
  • Query Only 模式:只编码 URL 参数值部分(等号后内容),保留键名、符号和路径结构不变
  • 实时防抖:300ms 自动编码解码,无需点击按钮,输入即出结果
  • 字符统计:实时显示输入字符数,方便核对 API 参数长度限制

使用方法

  1. Paste URL or text to encode/decode
  2. Select direction (Encode/Decode) and mode (Component/URI/full/RFC 3986)
  3. Enable batch mode for multi-line, or Query Only for parameter values only
  4. Copy the highlighted result for API requests or URL building

常見問題

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.

什麼是 URL 編碼?

URL 編碼(百分號編碼)將 URL 中非安全字元轉換為 %XX 格式,URL 只能使用 ASCII 字母數字和 -_.~,其他字元(中文、空格、符號)必須編碼。

encodeURIComponent 編碼最徹底(含 &、=、?),適合參數值;encodeURI 保留 URL 結構字元,適合完整 URL。

RFC 3986 將波浪號 ~ 視為安全字元不編碼,是目前推薦標準。

Query Only 模式只編碼參數值,保留鍵名和符號。

所有計算在瀏覽器本機完成,資料不上傳。

术语表

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

CharacterDescriptionencodeURIComponentencodeURIRFC 3986
spaceSpace%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

EncodedCharURL 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

Code Examples

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());
    }
}

Authoritative References