URL 編碼
高亮为百分号编码字节。
免費線上 URL 編碼解碼工具,支援 encodeURIComponent/encodeURI/RFC 3986 等模式,編碼高亮,批量模式,Query Only 模式。瀏覽器本機處理。
高亮为百分号编码字节。
免費線上 URL 編碼解碼工具,支援 encodeURIComponent/encodeURI/RFC 3986 等模式,編碼高亮,批量模式,Query Only 模式。瀏覽器本機處理。
encodeURIComponent encodes all non-safe characters including &, =, ? — suitable for individual parameter values. encodeURI preserves URL structural characters (: / ? #) — suitable for encoding complete URLs.
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 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.
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.
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.
Highlights %XX-encoded characters in amber, helping you understand encoding rules: letters/digits are safe and not encoded, while Chinese and special symbols are.
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 中非安全字元轉換為 %XX 格式,URL 只能使用 ASCII 字母數字和 -_.~,其他字元(中文、空格、符號)必須編碼。
encodeURIComponent 編碼最徹底(含 &、=、?),適合參數值;encodeURI 保留 URL 結構字元,適合完整 URL。
RFC 3986 將波浪號 ~ 視為安全字元不編碼,是目前推薦標準。
Query Only 模式只編碼參數值,保留鍵名和符號。
所有計算在瀏覽器本機完成,資料不上傳。
| 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 | ~ |
| 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 |
// 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());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)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());
}
}