抓取詳情圖片,包含中文無法上傳到oss系統,想到將url地址中的漢字進行轉碼
public static String getUtf8Url(String url) {
char[] chars = url.toCharArray();
StringBuilder utf8Url = new StringBuilder();
final int charCount = chars.length;
for (int i = 0; i < charCount; i++) {
byte[] bytes = ("" + chars[i]).getBytes();
if (bytes.length == 1) {
utf8Url.append(chars[i]);
}else{
try {
utf8Url.append(URLEncoder.encode(String.valueOf(chars[i]), "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
return utf8Url.toString();
}