Tag Archives: special

Java handles special characters in URL

The URL can’t display some special symbols, so the encoding will be used at this time. The encoding format is: a percent sign followed by the ASCII (hexadecimal) code value of the corresponding character. For example, the encoding value of a space is% 20. (ASCII reference)
some characters have special meanings in the URL, and the basic coding rules are as follows:
special meaning
hexadecimal value
1. + indicates empty space (spaces cannot be used in the URL)% 20
2/ Separate directory and subdirectory% 2F
3.?separate actual URL and parameter% 3F
4.% specify special character% 25
2 5. # indicates the separator% 26 between the parameters specified in the bookmark% 23
6. & amp; URL

For example: http://192.168.xxx.xxx/source/20190112 121000.txt

Note: such a URL cannot be successfully requested because the URL contains special words. The example URL contains special characters for spaces, so it needs to be converted to http://192.168.xxx.xxx/source/20190112%20121000.txt

Such a URL can request success.

Supplementary points:

Encoding and decoding functions of URL in Java java.net.URLEncoder . encode (string s) and java.net.URLDecoder . decode (string s);
URL encoding and decoding functions in JavaScript
escape (string s) and unescape (string s);