percent encoding

Jongwon Woo
2 min readJan 11, 2023

--

TL;DR

퍼센트 인코딩을 해야 하는 상황이 오면 서버 API 개발자와 테스트하면서 결과를 확인해라.

post

https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST

application/x-www-form-urlencoded: the keys and values are encoded in key-value tuples separated by ‘&’, with a ‘=’ between the key and the value. Non-alphanumeric characters in both keys and values are percent encoded: this is the reason why this type is not suitable to use with binary data (use multipart/form-data instead)

application/x-www-form-urlencoded

Percent-encoding

https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding

Depending on the context, the character ‘ ’ is translated to a ‘+’ (like in the percent-encoding version used in an application/x-www-form-urlencoded message), or in ‘%20’ like on URLs.

https://developer.apple.com/documentation/foundation/nsstring/1411946-addingpercentencoding

https://datatracker.ietf.org/doc/html/rfc3986#section-2.1

https://en.wikipedia.org/wiki/Percent-encoding

https://en.wikipedia.org/wiki/URL

Internationalized URL

The URL path name can also be specified by the user in the local writing system. If not already encoded, it is converted to UTF-8, and any characters not part of the basic URL character set are escaped as hexadecimal using percent-encoding; for example, the Japanese URL http://example.com/引き割り.html becomes http://example.com/%E5%BC%95%E3%81%8D%E5%89%B2%E3%82%8A.html.

https://github.com/Alamofire/Alamofire/blob/master/Documentation/Usage.md#get-request-with-url-encoded-parameters

Configuring the Encoding of Spaces

Older form encoders used + to encode spaces and some servers still expect this encoding instead of the modern percent encoding, so Alamofire includes the following methods for encoding spaces:

https://www.ietf.org/rfc/rfc2396.txt

https://www.w3.org/TR/2003/REC-xforms-20031014/slice11.html#serialize-urlencode

The encoding of EltName and value are as follows: space characters are replaced by +, and then non-ASCII and reserved characters (as defined by [RFC 2396] as amended by subsequent documents in the IETF track) are escaped by replacing the character with one or more octets of the UTF-8 representation of the character, with each octet in turn replaced by %HH, where HH represents the uppercase hexadecimal notation for the octet value and % is a literal character. Line breaks are represented as “CR LF” pairs (i.e., %0D%0A).

--

--