Server. urlencode and httputility. urlencode

Source: Internet
Author: User
Tags alphanumeric characters classic asp

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.UrlEncodeWill 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.