学子网站建设,功能型网站开发,北京小型网站建设,wordpress谷歌字体优化遇到java里的URLEncoder.encode方法编码后与javascript的encodeURIComponent方法的结果有点不一样#xff0c;找了一下资料#xff0c;原来URLEncoder实现的是HTML形式的规范#xff0c;jdk文档里这么说#xff1a; Utility class for HTML form encoding. This class cont…遇到java里的URLEncoder.encode方法编码后与javascript的encodeURIComponent方法的结果有点不一样找了一下资料原来URLEncoder实现的是HTML形式的规范jdk文档里这么说 Utility class for HTML form encoding. This class contains static methods for converting a String to the application/x-www-form-urlencoded MIME format. 看到aliyun-oss-sdk的HttpUtil里是这么做的 /*** Encode a URL segment with special chars replaced.*/public static String urlEncode(String value, String encoding) {if (value null) {return ;}try {String encoded URLEncoder.encode(value, encoding);return encoded.replace(, %20).replace(*, %2A).replace(~, %7E).replace(/, %2F);} catch (UnsupportedEncodingException e) {throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString(FailedToEncodeUri), e);}} 参考URLEncoder not able to translate space character 转载于:https://www.cnblogs.com/liqipeng/p/7997795.html