public static String encode(String url, String encode) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); StringBuilder noAsciiPart = new StringBuilder(); for (int i = 0; i < url.length(); i++) { char c = url.charAt(i); if (c > 255) { noAsciiPart.append(c); } else { if (noAsciiPart.length() != 0) { sb.append(URLEncoder.encode(noAsciiPart.toString(), encode)); noAsciiPart.delete(0, noAsciiPart.length()); } sb.append(c); } } return sb.toString(); }
原文地址:https://www.cnblogs.com/nanahome/p/11141170.html
时间: 2024-11-11 02:25:42