URLEncoder.encode问题
生活随笔
收集整理的这篇文章主要介绍了
URLEncoder.encode问题
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
遇到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
创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖总结
以上是生活随笔为你收集整理的URLEncoder.encode问题的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 映射网络驱动器失败的解决办法
- 下一篇: 获取要素集中字段的唯一值