Koder URL - Bezpieczne Kodowanie URL
Powrót do NarzędziO Kodowaniu URL
Kodowanie URL konwertuje znaki do formatu bezpiecznego dla Internetu.
Kiedy Używać
- Przesyłanie danych formularzy
- Kodowanie parametrów URL
- Budowa ciągu zapytania
Czym jest Kodowanie URL?
Kodowanie URL to mechanizm konwersji znaków do formatu ASCII.
How URL Encoding Works
The encoding process converts each unsafe character to its hexadecimal ASCII representation, prefixed with a percent sign (%). This ensures all characters can be safely transmitted in URLs.
Encoding Rules
Reserved characters (like ?, &, =) and unsafe characters (like spaces, quotes) are encoded. Safe characters (A-Z, a-z, 0-9, -, ., _, ~) remain unchanged.
Przykłady Kodowania URL
Znaki Specjalne
Oryginał: Witaj Świecie!
Zakodowane: Witaj%20%C5%9Awiecie%21
Email Address
Oryginał: user@example.com
Zakodowane: user%40example.com
Query Parameters
Oryginał: name=John Doe&age=25
Zakodowane: name%3DJohn%20Doe%26age%3D25
Special Symbols
Oryginał: $100 & 50% off
Zakodowane: %24100%20%26%2050%25%20off
Szczegóły Techniczne
Reserved Characters
: / ? # [ ] @ ! $ & ' ( ) * + , ; =
Unsafe Characters
Space " < > % { } | \ ^ ` [ ]
Encoding Format
Each encoded character follows the pattern: % + two hexadecimal digits representing the ASCII value.
Space (ASCII 32) = %20, @ (ASCII 64) = %40
Przypadki Użycia
Form Data Submission
Encode form data before sending HTTP POST requests to ensure special characters are properly transmitted.
URL Parameter Construction
Create safe URL parameters by encoding values that may contain spaces or special characters.
API Request Building
Prepare data for RESTful API calls where parameters need to be URL-safe for GET requests.
Web Development
Ensure user-generated content can be safely included in URLs without breaking the request structure.
Najlepsze Praktyki
Always Encode User Input
Never trust user input - always encode data before including it in URLs to prevent injection attacks.
Encode Only When Necessary
Don't encode already-encoded strings to avoid double-encoding issues that can corrupt data.
Use Proper Character Set
Ensure your application uses consistent character encoding (UTF-8) throughout the encoding process.
Validate Before Encoding
Validate and sanitize input data before encoding to catch potential security issues early.
Test with Edge Cases
Test your encoding with special characters, unicode, and edge cases to ensure robust handling.
Document Encoding Requirements
Clearly document which parts of your API or application require URL-encoded input.
Rozwiązywanie Problemów
Double Encoding Problem
URLs become corrupted when encoding already-encoded strings (e.g., %20 becomes %2520).
Check if data is already encoded before applying URL encoding. Implement detection logic.
Character Set Mismatch
Non-ASCII characters display incorrectly after encoding due to character set issues.
Ensure consistent UTF-8 encoding throughout your application and specify charset in headers.
Plus Sign Confusion
Plus signs (+) in URLs may be interpreted as spaces in form data encoding.
Use %2B for literal plus signs in URLs, or + for spaces in application/x-www-form-urlencoded.
Reserved Character Problems
Reserved characters break URL structure when not properly encoded.
Always encode reserved characters (?, &, =, etc.) when they appear in parameter values.