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问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 映射网络驱动器失败的解决办法
- 下一篇: 获取要素集中字段的唯一值