# Data : URL Encoding - https://datatracker.ietf.org/doc/html/rfc3986 - https://en.wikipedia.org/wiki/Percent-encoding *aka "percent-encoding"* > [!NOTE] > Percent-encoding a character involves converting the character to its corresponding byte value in ASCII, representing that value as a pair of hexadecimal digits, and pre-pending a percent sign. > > `'+'` = ASCII 43 = 0x2B -> `'%2B'` Also used for HTML form data. **Unreserved Characters** -> `A-Za-z0-9-._~` **Reserved Characters** ``` ! %21 # %23 $ %24 & %26 ' %27 ( %28 ) %29 * %2A + %2B , %2C / %2F : %3A ; %3B = %3D ? %3F @ %40 [ %5B ] %5D ``` - Other characters in a URI must be percent-encoded. - Also, when using a reserved character in a context where it has special meaning, the character must be _percent-encoded_. - For example, if a path segment had a literal `'/'` within it. - Counter-example: Within the query portion, = and & have special meaning, but / does not, and therefore need not be percent-encoded. - Because % is the escape character, a literal `'%'` must also be encoded. (`'%'` = ASCII 37 = 0x25 -> `%25`) **Common Character Encodings** ``` %20 (space character) " %22 % %25 - %2D . %2E < %3C > %3E \ %5C ^ %5E _ %5F ' %60 { %7B | %7C } %7D ~ %7E £ %C2%A3 € %E2%82%AC ``` #### HTML Form Data - When sent in a GET request, it is included in the query component of the URI using the above syntax. - When sent in a POST request or via email, the data is placed in the body of the message, and `application/x-www-form-urlencoded` is included in the message's Content-Type header. The encoding used is based on an early version of the percent-encoding rules with a number of modifications such as newline normalization and replacing spaces with `'+'` instead of `'%20'`. ## Python See: [[Tech/Python/Core Library/Web|Python : Core : Web]]