Encode or decode a URL, a query value, or a form body. UTF-8 matches encodeURIComponent. Pick GBK or another encoding when the other side is not Unicode.
A URL is several pieces with different rules. The path may contain a slash that must stay a slash. A query value may contain a slash that must become %2F. A form body uses + for a space, while a query string usually uses %20. Encoding the whole string with the wrong function is the usual reason a link opens the wrong page.
encodeURIComponent. Use it for one parameter: a search term, an id, a redirect target.encodeURI. It leaves : / ? # alone and only escapes spaces and non-ASCII characters. Use it when you already have a full address.application/x-www-form-urlencoded. Spaces become +. Use it when you are building a POST body, not a link.%20 already means space and a literal plus is rare.% is not followed by two hex digits. That often means the string was decoded once already, or it was cut at a %.Space is %20 in a URL and + in a form. A literal plus in a query value must be %2B, or the server will read it as a space. & and = must be encoded inside a value or they start the next parameter. With UTF-8, which is the default and what encodeURIComponent uses, Chinese and emoji become one % sequence per byte. 北京 is not one escape; it is several. If a legacy server expects GBK or Big5, choose that encoding: the same characters become different percent sequences. Hex treats the box as raw bytes and percent-encodes those bytes.
Do not encode a full URL with the query-value style. https:// becomes https%3A%2F%2F and the browser will not treat it as an address. Encode the pieces, then join them. For the bytes behind those percents, see string to bytes. For Base64, which is a different encoding, see Base64.
You used the form-body style. That is correct for HTML forms and wrong for most links. Switch to Query value.
The string was encoded twice. Decode again. Stop when the text is readable.
No. Split on &, encode each value, and keep the & and = as separators. “One value per line” is the safe way to do a list.