xml에서 UTF-8 한글 인식하기
작성자 관리자 작성시간 2009-03-11 10:14:16
 

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();


목록 | 입력 | 수정 | 답변 | 삭제