URLEncode和URLDecode用于完成普通字符串和 application/x-www-from-urlencoded
MIME字符串之间的相互转化
如果传递的字符串中包含非西欧字符的字符串,会被转化成%XX%XX XX为十六进制的数字
- try {
- // 将application/x-www-from-urlencoded字符串转换成普通字符串
- String keyWord = URLDecoder.decode("%C4%E3%BA%C3", "GBK");
- System.out.println(keyWord); //输出你好
- // 将普通字符创转换成application/x-www-from-urlencoded字符串
- String urlString = URLEncoder.encode("你好", "GBK"); //输出%C4%E3%BA%C3
- System.out.println(urlString);
- } catch (UnsupportedEncodingException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
try {
// 将application/x-www-from-urlencoded字符串转换成普通字符串
String keyWord = URLDecoder.decode("%C4%E3%BA%C3", "GBK");
System.out.println(keyWord); //输出你好
// 将普通字符创转换成application/x-www-from-urlencoded字符串
String urlString = URLEncoder.encode("你好", "GBK"); //输出%C4%E3%BA%C3System.out.println(urlString);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} </pre><br><br><p></p>
</div>
</div>