title: How to send deferent language text over HTTP using java
body: <p>Im trying to post a json from one server to another server using HTTP Connection
  I have a model</p>
  <pre><code>Test{
      private String transId;
      private String msisdn;
      private String msg;
      private String senderId;
      private String customerid;
      private String customerName;
      private String actiontypes;
  } 
  </code></pre>
  <p>In <strong>msg</strong> filed i will send a message in deferent language templates based on requested language.</p>
  <pre><code>{&quot;transId&quot;:null,&quot;msisdn&quot;:null,&quot;msg&quot;:&quot;क्या हाल है&quot;,&quot;senderId&quot;:null,&quot;customerid&quot;:null,&quot;customerName&quot;:null,&quot;actiontypes&quot;:null}
  </code></pre>
  <p>in the above example im sending hindi message.</p>
  <p>Here is my code to post data</p>
  <pre><code>         GrameenVerLangRequestModel obj = new GrameenVerLangRequestModel();
           obj.setMsg(&quot;क्या हाल है&quot;);
           String responseFromGrameen = 
           notification.postVernacularMessageToGrameen(gson.toJson(obj),logger); 
  </code></pre>
  <p>here is the post method</p>
  <pre><code>public String postVernacularMessageToGrameen(String body, Logger logger) {
          logger.info(&quot;Start-postVernacularMessageToGrameen&quot;);
          try {
              StringBuffer responsebuf = new StringBuffer();
              URL obj = new URL(url);
              
              logger.info(&quot;Data :&quot;+body);
              System.out.println(&quot;Data :&quot;+body);
              HttpURLConnection con = (HttpURLConnection) obj .openConnection();
              con.setRequestMethod(&quot;POST&quot;);
              con.setRequestProperty(&quot;Content-Type&quot;, &quot;application/json; charset=UTF-8&quot;);
          
              // Send post request
              con.setDoOutput(true);
              DataOutputStream wr = new DataOutputStream(con.getOutputStream());
              
              wr.writeBytes(body);
              wr.flush();
              wr.close();
              int responseCode = con.getResponseCode();
              if(responseCode == 200){
                  BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
                  String inputLine;
                  while ((inputLine = in.readLine()) != null) {
                      responsebuf.append(inputLine);
                  }
                  in.close();
                  logger.info(&quot;Response from Server : &quot; + responsebuf);
                  return responsebuf.toString();
                  } else {
                      return responseCode+&quot;&quot;;
              }
          }catch (Exception e) {
              e.printStackTrace();
              logger.info(e);
          }finally {
          logger.info(&quot;End-postVernacularMessageToGrameen&quot;);
          }
          return null;
      }
  </code></pre>
  <p>here is the body before i post to another server</p>
  <pre><code>Data :{&quot;transId&quot;:null,&quot;msisdn&quot;:null,&quot;msg&quot;:&quot;क्या हाल है&quot;,&quot;senderId&quot;:null,&quot;customerid&quot;:null,&quot;customerName&quot;:null,&quot;actiontypes&quot;:null}
  </code></pre>
  <p>after posting to the intended server where i am receiving like</p>
  <pre><code>Data received:{&quot;transId&quot;:null,&quot;msisdn&quot;:null,&quot;msg&quot;:&quot;M/&gt; 9&gt;2 9H&quot;,&quot;senderId&quot;:null,&quot;customerid&quot;:null,&quot;customerName&quot;:null,&quot;actiontypes&quot;:null} 
  </code></pre>
  <p><strong>&quot;msg&quot;:&quot;M/&gt; 9&gt;2 9H&quot;</strong> how to get it readable in intended language.</p>
  <p>Can anyone help me with this ?.</p>
  <p>Thanks.</p>
  <p><strong>EDIT :</strong>
  i'm trying to decode at receiving server side as below but it gives same response</p>
  <p><strong>utf8EncodedString :{&quot;transId&quot;:null,&quot;msisdn&quot;:null,&quot;msg&quot;:&quot;M/&gt; 9&gt;2 9H&quot;,&quot;senderId&quot;:null,&quot;customerid&quot;:null,&quot;customerName&quot;:null,&quot;actiontypes&quot;:null}</strong></p>
  <pre><code>    String rawString = receivedData;
      ByteBuffer buffer = StandardCharsets.UTF_8.encode(rawString); 
       
      String utf8EncodedString = 
      StandardCharsets.UTF_8.decode(buffer).toString();
      System.out.println(&quot;utf8EncodedString :&quot;+utf8EncodedString);
  </code></pre>