|
1. UTF-8ÀÎ °æ¿ì
String encStr = method.getResponseBodyAsString();
2. ÀÎÄÚµù üũÇÑ´Ù.
public static String EnCodeCheck(String contentall) throws IOException {
String content = contentall.substring(0, contentall.length());
int index = content.indexOf("encoding");
if (index == -1)
return "UTF-8";
int index1 = content.indexOf("=", index);
int index2 = content.indexOf("?>", index);
String encoding = content.substring(index1 + 1, index2); // "UTF-8"
encoding = encoding.replace('\"', ' ').trim();
return encoding;
}
3. ÀÎÄÚµù °ªÀÌ "UTF-8" ÀÏ °æ¿ì ¾Æ·¡¿Í °°ÀÌ º¯È¯ÇÕ´Ï´Ù.
String resultStr = new String(encStr.getBytes("8859_1"), "UTF8");
responseBody = resultStr.getBytes()
4. "UTF-8"ÀÌ ¾Æ´Ò °æ¿ì getResponseBody()¸Þ¼Òµå·Î byte[] ¸¦ ¹ÝȯÇÕ´Ï´Ù.
responseBody = method.getResponseBody();
String encStr = method.getResponseBodyAsString();
String encode = EnCodeCheck(encStr);
System.out.println(">>>>>>>>>>>>>>encode="+encode);
String resultStr = new String(encStr.getBytes("8859_1"), "UTF8");
byte[] responseBody = resultStr.getBytes();
|