// 编码
String encodeUrl = URLEncoder.encode(content, “utf-8”);
// 解码
String decodeUrl = URLDecoder.decode(encodeUrl, “utf-8”);
例如get 表单请求url
url:“https://loacalhost:8086/open?content=”+URLEncoder.encode(content, “UTF-8”)
如下:
try {
String content = "中文中文中文中文中文";
//通过utf-8编码把中文字符串转化为application/x-www-form-urlencodedMIME字符串
String encodeUrl = URLEncoder.encode(content, "utf-8");
//同样通过utf-8编码把application/x-www-form-urlencodedMIME字符串解码为原来的字符串
String decodeUrl = URLDecoder.decode(encodeUrl, "utf-8");
} catch (Exception e) {
e.printStackTrace();
}