今天看公司项目的代码,对图片发送异步请求的URL的编码问题,看了看,又查了一些资料,希望能对URL编码有疑惑的人了解一下吧。 AAAAAAAAAAAAAAAA:首先我是用java的URLencode.encode方法对其进行编码的。 它的说明是 Encodes a given string s in a x-www-form-urlencoded string using the specified encoding schemeenc.
All characters except letters ('a'..'z', 'A'..'Z') and numbers ('0'..'9') and characters '.', '-', '*', '_' are converted into their hexadecimal value prepended by '%'. For example: '#' -> #. In addition, spaces are substituted by '+'
BBBBBBBBBBBBBBB:但是呢URL传输需要字符串的规则是:
1:Characters in the unreserved character set as defined by(ALPHA, DIGIT, "-", ".", "_", "~") MUST NOT be encoded.
2: All other characters MUST be encoded.
3:The two hexadecimal characters used to represent encoded characters MUST be upper case.
不知道大家看出来没有有何区别,首先URLencode.encode 是'.', '-', '*', '_'符号不编码,而URL传输需要字符串是 "-", ".", "_", "~"不编码。 那么可以这样的
String URL="www.baidu.com";
String ENCODING="utf-8";
String strURL= URLEncoder.encode(URL, ENCODING).replace("*","*").replace("~", "~").replace("+"," ");
|
|
来自: 昵称23020986 > 《待分类1》