java.net.URLEncoder.encode(some_URL, "UTF-8")
/**
* Return a URL-encoded string version of the argument passed in.
*/
function urlEncode(arg)
{
try {
return java.net.URLEncoder.encode(arg,"UTF-8");
} catch (err) {
// Fall-through
}
// If UTF-8 failed, just use the default encoding.
return java.net.URLEncoder.encode(arg);
}
|
Character Types
|
Coding Requirements/Considerations
|
|---|---|
|
ASCII Control Characters
|
All characters within the range 00-1F and 7F must be encoded.
|
|
Reserved Characters
|
The following special characters are reserved:
• dollar sign ($) encode %24
• ampersand (&) encode %26
• plus sign (+) encode %2B
• comma (,) encode %2C
• forward slash mark (/) encode %2F
• colon (:) encode %3A
• semi-colon (;) encode %3B
• equal sign (=) encode %3D
• question mark (?) encode %3F
• at sign (@) encode %40
• star ( * ) encode %2A
• exclamation ( ! ) encode %21
|
|
Unsafe Characters
|
Some special characters present the possibility of being misunderstood within URLs, for example, they could be incompatible or unreliable. PTC recommends encoding the following characters:
• blank space ( ) encode %20 (especially multiple spaces)
• quotation marks (“”) encode %22
• less than sign (\<) encode %3C
• greater than sign (\>) encode %3E
• number sign (#) encode %23
• percent (%) encode %25
• left brace ({) encode %7B
• right brace (}) encode %7D
• vertical bar/pipe (|) encode %7C
• backslash (\) encode %5C
• caret (^) encode %5E
• tilde (~) encode %7E
• left bracket ([) encode %5B
• right bracket (]) encode %5D
• grave accent (`) encode %60
|
|
Supported Special Characters
|
The following special characters are allowed and do not need encoding:
• hyphen ( - ) encode -
• underscore ( _ ) encode _
|
|
Non-ASCII Characters
|
All non-ASCII characters must be encoded. This includes the entire top half of the ISO-Latin set 80-FF hexadecimal.
|
|
Unicode Characters
|
All unicode characters must be encoded. This includes everything above FF.
|