From a java-servlet I send a request to a third-party GET web server, I get the html code in response, I stuff this code into a string. I look at the line-a Russian letters in it in the form of diamonds with questions. In the html document itself, the encoding is not specified anywhere. Therefore, manually re-encode the string in UTF-8. Did not help.
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { String url = "http://meteonovosti.ru/index.php?index=8&value=26063"; URL obj = new URL(url); HttpURLConnection connection = (HttpURLConnection) obj.openConnection(); connection.setRequestMethod("GET"); BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); String answer = response.toString(); System.out.println("Оригинальный ответ: "+answer); answer = new String(answer.getBytes(), "UTF-8" ); System.out.println("После перекодирования: "+answer); Both outputs are the same (missing pieces of html code):
Original answer: - :
After recoding: - :
In the Eclipse settings, it is indicated to use UTF-8 everywhere. What do I need to do to get Russian letters?
