All these methods relate to RFC 2396
, that defines the syntax of Uniform Resource Identifiers (or URI) and, in the case of Urlencode, also the RFC 1738
(defining Uniform Resource Locators, or Urls).
Urlencode
When to use: When you need to ensure that a URL is valid, or when you need to pass a URL as a parameter within another URL.
How it works: Converts all control or reserved characters defined in RFC 1738
for its coded equivalents, thus preventing markers such as whitespace (which could define the end of a resource’s name) or backslash (which could define a protocol or credentials, depending on the position) from being misinterpreted.
Escapeuristring
When to use: When you need to pass a URI instead of a URL.
How it works: Converts all characters (except those described as non-reserved in RFC 2396
) for hexadecimal representation. (this behavior changes if Iris or IDN interpretation is enabled). Because the character set reserved for Uris is different from the set for Urls, some valid Urls can be misinterpreted (mainly by using the plus sign [+].)
Escapedatastring
When to use: When you need to pass data in a URI.
How it works: Performs the same transformations of EscapeUriString
, but includes control characters considered valid for a URI in the conversion in order to allow the data to be correctly interpreted as content and not as identifiers.
You can find some conversion tables between formats here.