2014-03-05 4 views
2

다음 코드가 있습니다. 응답을 받으면 문자가 잘못되었습니다. 나는 "UTF-8"로 응답을 받고 싶다. 어떻게 그리고 어디에서 아래 코드를 작성할 수 있습니까?HTTP 응답 받기 utf-8

감사


URL httpPost = 새 URL (URL);

 HttpsURLConnection connection = (HttpsURLConnection) httpPost.openConnection(); 
     connection.setRequestProperty("Content-Type", "application/json"); 
     connection.setRequestMethod("POST"); 

     connection.setDoOutput(true); 

     connection.setDoInput(true); 

     connection.getOutputStream().write(params.getBytes(Charset.forName("UTF-8"))); 
     connection.getOutputStream().flush(); 

     BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8")); 
     String inputLine; 
     StringBuffer response = new StringBuffer(); 

     while ((inputLine = in.readLine()) != null) { 

      response.append(inputLine); 

     } 

     try { 

      String responseFromServer = response.toString(); 

      dealsResponse = Utils.mapper.readValue(responseFromServer, GetDealsResponse.class); 

     } finally { 
      in.close(); 

     } 
+0

HTTP 추적을 얻습니다. 어쩌면 그 반응은 실제로 깨 졌는가? 어떤 경우에는 서버를 수정해야합니다. –

+0

필자는 이렇게 입력 라인을 추적합니다. { "message": "Sunucu hatas?", "success": false} – serkan

+0

원시 HTTP 추적이 필요합니다. –

답변

0

connection.setRequestProperty ("Accept-Charset", "UTF-8");