URL-Encoder / Decoder/ Kodieren · Dekodieren · Formular
URLs mit encodeURIComponent, encodeURI oder Formular-Encoding in Echtzeit kodieren und dekodieren.
Alle Sonderzeichen kodieren (empfohlen, für Query-Parameter)
%20 / +!%21"%22#%23%%25&%26'%27+%2B/%2F=%3D?%3F@%40Hat dieses Tool Ihr Problem gelöst?
Was ist URL-Kodierung
Die URL-Kodierung (Prozent-Kodierung) wandelt Sonderzeichen in `%` gefolgt von zwei Hexadezimalziffern um. URLs允许 nur Buchstaben, Zahlen und少数 Symbole (`-_.~`). Andere Zeichen wie Leerzeichen (%20) oder Nicht-ASCII-Zeichen müssen kodiert werden. Browser kodieren URLs in der Adresszeile automatisch, aber beim programmatischen Erstellen von URLs müssen Sie die Kodierung手动 handhaben.
Gängige Szenarien für URL-Kodierung
Übergeben von Sonderzeichen in Abfrageparametern (z. B. Suchbegriffe mit `&` oder `=`), Formular-Datenübermittlung (POST标准mäßig URL-Kodierung), API-Anfragen mit JSON oder Nicht-ASCII-Parametern und OAuth-Callback-URLs. Verwenden Sie `encodeURIComponent()` in JavaScript oder `urllib.parse.quote()` in Python.
Code-Beispiele
// Encode a query parameter value
encodeURIComponent("Hello World! 中文")
// "Hello%20World!%20%E4%B8%AD%E6%96%87"
// Build a full query string (recommended)
const params = new URLSearchParams({
q: "hello world",
lang: "zh-CN",
page: "1",
});
params.toString()
// "q=hello+world&lang=zh-CN&page=1"
// Decode
decodeURIComponent("Hello%20World%21")
// "Hello World!"from urllib.parse import (
quote, unquote,
urlencode, quote_plus
)
# Encode single value
quote("Hello World! 中文")
# 'Hello%20World%21%20%E4%B8%AD%E6%96%87'
# Form encoding (spaces → +)
quote_plus("hello world")
# 'hello+world'
# Build query string
urlencode({"q": "hello world", "page": 1})
# 'q=hello+world&page=1'
# Decode
unquote("Hello%20World%21") # 'Hello World!'import "net/url"
// Encode a path segment
url.PathEscape("hello world/中文")
// "hello%20world%2F%E4%B8%AD%E6%96%87"
// Encode a query value
url.QueryEscape("hello world")
// "hello+world"
// Build query string
params := url.Values{}
params.Set("q", "hello world")
params.Set("lang", "zh-CN")
params.Encode()
// "lang=zh-CN&q=hello+world"
// Parse a URL
u, _ := url.Parse("https://example.com/search?q=hello+world")
u.Query().Get("q") // "hello world"# curl handles encoding automatically with --data-urlencode
curl -G https://api.example.com/search \
--data-urlencode "q=hello world 中文" \
--data-urlencode "page=1"
# Manual percent-encoding with Python
python3 -c "
import sys
from urllib.parse import quote
print(quote(sys.stdin.read().strip()))
" <<< "hello world 中文"
# Using jq to build encoded JSON body
curl -X POST https://api.example.com \
-H 'Content-Type: application/json' \
-d "$(jq -n --arg q 'hello world' '{query: $q}')"