title: Encode/Decode HttpPost UTF-8 Java
body: <p>I am having troubles trying to send post data in utf8 format from the client to my server.</p>
  
  <p>I have read a lot about this topic but I can´t find the solution. I am sure that I am missing something basic.</p>
  
  <p>Here is my client code to make the post request</p>
  
  <pre><code>public static PostResponse post(String url, String data) {
          PostResponse response = new PostResponse();
          try {
              // 1. create HttpClient
              HttpClient httpclient = new DefaultHttpClient();
  
              // 2. make POST request to the given URL
              HttpPost httpPost = new HttpPost(url);
              httpPost.setHeader("Content-Type", "text/plain; charset=UTF-8");
  
              // 3. set string to StringEntity
              StringEntity se = new StringEntity(data);
  
              // 4. set httpPost Entity
              httpPost.setEntity(se);
  
              // 5. Execute POST request to the given URL
              HttpResponse httpResponse = httpclient.execute(httpPost);
  
          } catch (IOException e) {
  
          }
          return response;
  
      }
  </code></pre>
  
  <p>This is the code in my server side to receive the text in utf8 (Polish characters are not appearing, I am getting "?" instead.)</p>
  
  <pre><code>protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
  try {
              BufferedReader reader;
              reader = req.getReader();
              Gson gson = new Gson();
              msg = gson.fromJson(reader, MsgChat.class); //String in the client was json
          } catch (IOException e) {
  
          }
  }
  </code></pre>
  
  <p>I wrote only the relevant code.</p>
  
  <p>I would appreciate any help regarding this.
  Thanks.</p>