Server. urlencode MethodThe URL encoding rules will be applied to a string, including escape characters.
Urlencode converts the following characters:
- Space () is converted to the plus sign (+)
- Non-alphanumeric characters are converted to their hexadecimal Representation
Example:
<% Response. Write (server. urlencode ("http://www.microsoft.com") %>
The output result is
HTTP % 3A % 2f % 2 fwww % 2 emicrosoft % 2 ECOM
Httputility. urlencode MethodIt can be used to encode the entire URL, including query-string values ). when passing in HTTP stream with space and other punctuation characters, they may be misunderstood as the end of the stream. URL encoding converts the characters that are not allowed in these URLs into equivalent character entities. URL Decoding performs reverse operations.
You can use the urlencode () method or urlpathencode () method. However, the returned values of these two methods are different.
The urlencode () method converts spaces to the plus sign (+).
The urlpathencode () method converts spaces to strings"% 20", Which is also the hexadecimal representation of space.
You should use the urlpathencode () method when partially encoding the path in the URL to ensure that a legal URL is obtained no matter which platform or browser performs decoding.
Differences between the two methods
There is no specific difference between them. The existence of server. urlencode is because it needs to be compatible with the classic ASP.
HttpServerUtility.UrlEncode
Will be called internallyHttpUtility.UrlEncode.
From msdn:
URL encoding ensures that all browsers will correctly transmit text in URL strings. characters such as a question mark (?), Ampersand (&), slash mark (/), and spaces might be truncated or upted by Some browsers. as a result, these characters must be encoded in <A> tags or in query strings where the strings can be re-sent by a browser in a request string.
UrlencodeIs a convenient way to accessHttputility...:. urlencodeMethod at run timeFrom an ASP. NET application.Internally,UrlencodeUsesHttputility...:. urlencodeTo encode strings.
Server. urlencode Method
Http://msdn.microsoft.com/en-us/library/ms525738.aspx
Httputility. urlencode method (string)
Http://msdn.microsoft.com/en-us/library/4fkewx0t.aspx
Httpserverutility. urlencode method (string)
Http://msdn.microsoft.com/en-us/library/zttxte6w.aspx
Server. urlencode vs. httputility. urlencode
Http://stackoverflow.com/questions/602642/server-urlencode-vs-httputility-urlencode