title: URLConnection Character Encoding
body: <p>I am trying to read a JSON string:</p>
  
  <pre><code>{
    "also_known_as": [
      "Сильвестр Сталлоне"
    ],
  
    "birthday": "1946-07-06",
    "deathday": "",
  }
  </code></pre>
  
  <p>over HTTP.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>URL url = new URL("url");
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestProperty("Accept-Charset", "UTF-8");//connection.setRequestProperty("Accept-Charset", "ISO-8859-1");
  BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  String line = "";
  StringWriter writer = new StringWriter();
  while((line=reader.readLine())!=null){
      writer.write(line);
  }
  reader.close();
  writer.close();     
  connection.disconnect();
  System.out.println(writer.toString());
  </code></pre>
  
  <p>But it is printing the string in console:</p>
  
  <pre><code>{
    "also_known_as": [
      "Ð¡Ð¸Ð»ÑŒÐ²ÐµÑ?Ñ‚Ñ€ Ð¡Ñ‚Ð°Ð»Ð»Ð¾Ð½Ðµ"
    ],
  
    "birthday": "1946-07-06",
    "deathday": "",
  }
  </code></pre>
  
  <p>I have also tried:</p>
  
  <pre><code>BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));//BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(), "ISO-8859-1"));
  </code></pre>
  
  <p>But no luck.</p>
  
  <p>My question is how can I set the character encoding of the URLConnection?</p>
  
  <p>Any information will be very helpful to me. </p>
  
  <p>Regards. </p>
  
  <hr>
  
  <p>Using Apache IOUtils I have tried this:</p>
  
  <pre><code>StringWriter writer = new StringWriter();
  IOUtils.copy(connection.getInputStream(), writer, "UTF-8");
  </code></pre>
  
  <p>But it is printing same result in the console of eclipse.</p>
  
  <hr>
  
  <p>Using Apache HttpClient:</p>
  
  <pre><code>DefaultHttpClient httpClient = new DefaultHttpClient();
  HttpGet getRequest = new HttpGet("http://api.themoviedb.org/3/person/16483?api_key=23e89da030a0ee8b25aaed20950a0c25");
  getRequest.addHeader("accept", "application/json");
  HttpResponse response = httpClient.execute(getRequest);
  StringWriter writer = new StringWriter();
  IOUtils.copy(response.getEntity().getContent(), writer, "UTF-8");
  System.out.println(writer.toString());
  </code></pre>
  
  <p>same result.</p>