The conversion method of URL spaces in Web-practical tips

Source: Internet
Author: User
Tags urlencode

Look at the URL is httputility.urlencode to convert the space to the "+" number, the reason to find the solution to the bug.
Reference:

Copy Code code as follows:

filename = httputility.urlencode (filename, Encoding.UTF8);
FileName = Filename.replace ("+", "%20");

With replace replacement, although the problem is resolved, this is not a good method, if the folder or file name contains a "+" number will cause another bug to occur.
Best solution:

Use the Httputility.urlpathencode,urlpathencode method to perform the following steps:

1. The encoding logic of the Urlpathencode method applies only to the path portion of the URL (excluding the query string). The method assumes that the URL is encoded as a UTF-8 string.

2. Encode a non-space so that a subset of the first 128 ASCII characters is used in the resulting encoded string. Unicode has all character values of 128 and higher, or 32 and smaller, entered in the URL.

3. Enter a space as% 20.

You can enter a URL by using the UrlEncode method or the Urlpathencode method. However, the method returns a different result. The UrlEncode method converts each space character to a plus (+) character. The Urlpathencode method converts each space character to a string of% 20, a space represented by the hexadecimal notation. Use the Urlpathencode method when encoding the path portion of a URL to ensure a consistent decoded URL, regardless of the platform or browser performing the decoding. When you use the Urlpathencode method, the query string value is not entered. Therefore, any value (?) that can be passed through the question mark will not be entered in the string. If you must pass the URL, when the query string, use the UrlEncode method.

See many pages in the project use the Replace method, the query after all replaced with urlpathencode to reduce the occurrence of more bugs.

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.