Encodes a given string s
in a x-www-form-urlencodedstring using the specified encoding scheme enc
.
All characters except letters ('a'..'z', 'A'..'Z') and numbers('0'..'9') and characters '.', '-', '*', '_' are converted intotheir hexadecimal value prepended by '%'. For example: '#'-> #. In addition, spaces are substituted by '+'
BBBBBBBBBBBBBBB:但是呢URL传输需要字符串的规则是:
不知道大家看出来没有有何区别,首先URLencode.encode是'.', '-', '*', '_'符号不编码,而URL传输需要字符串是
StringURL="www.baidu.com";
String
String strURL= URLEncoder.encode(URL, ENCODING).replace("*","*").replace("~", "~").replace("+"," ");
//URLencode.encode 会将符号“~” 转变为“~”,所以我们要转回来,同时要将不转换的“*”
//转换一下。当然了,URLencode.encode 会将空格转换为“+”,但是“+”又不在BBBBBBBBBBBBBBB说明的
//"-", ".", "_", "~"里面,我们又必须将其转化。以上就是我的一点小小的看法,
//希望能帮到之前不懂的人。
//对了,我查询资料的网址告诉大家一下:
//href="http://tools.ietf.org/html/draft-hammer-oauth-10#section-3.6"
//为什么编码后需要再次处理
//http://oauth.googlecode.com/svn/code/java/core/commons/src/main/java/net/oauth/OAuth.java
//参考代码,进去后搜索RLEncoder.encode