title: Sending special characters (ë ä ï) in POST body with DataOutputStream in Android
body: <p>Im currently working on an Android app with heavy server side communication. Yesterday I got a bug report saying that the users aren't able to send (simple) special characters such as ëäï.</p>
  
  <p>I searched but didn't find anything helpful
  Possible duplicate ( without answer ):
  <a href="https://stackoverflow.com/questions/12388974/android-httpurlconnection-post-special-charactes-to-rest-clint-in-android">https://stackoverflow.com/questions/12388974/android-httpurlconnection-post-special-charactes-to-rest-clint-in-android</a></p>
  
  <p>My relevant code:</p>
  
  <pre><code>public void execute(String method) {
          HttpsURLConnection urlConnection = null;
          try {
              URL url = new URL(this.url);
              urlConnection = (HttpsURLConnection) url.openConnection();
              urlConnection.setRequestMethod(method);
              urlConnection.setReadTimeout(30 * 1000);
              urlConnection.setDoInput(true);
  
              if (secure)
                  urlConnection.setRequestProperty("Authorization", "Basic " + getCredentials());
  
              if (body != null) {
                  urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  
  
                  urlConnection.setFixedLengthStreamingMode(body.length());
                  urlConnection.setDoOutput(true);
                  DataOutputStream dos = new DataOutputStream(urlConnection.getOutputStream());
                  dos.writeBytes(body);
                  dos.flush();
                  dos.close();
              }
  
              responseCode = urlConnection.getResponseCode();
              message = urlConnection.getResponseMessage();
  
              InputStream in = null;
  
              try {
                  in = new BufferedInputStream(urlConnection.getInputStream(), 2048);
              } catch (Exception e) {
                  in = new BufferedInputStream(urlConnection.getErrorStream(), 2048);
              }
  
              if (in != null)
                  response = convertStreamToString(in);
  
          } catch (UnknownHostException no_con) {
              responseCode = 101;
          }catch (ConnectException no_con_2){
              responseCode = 101;
          }catch(IOException io_ex){
              if(io_ex.getMessage().contains("No authentication challenges found")){
                  responseCode = 401;
              }else
                  responseCode = 101;
          } catch (Exception e) {
              e.printStackTrace();
          } finally {
              if (urlConnection != null)
                  urlConnection.disconnect();
          }
      }
  </code></pre>
  
  <p><code>body</code> is a String ;-)</p>
  
  <p>Hope we can solve this together</p>
  
  <p>UPDATE:</p>
  
  <p>Tried:</p>
  
  <hr>
  
  <pre><code>writeUTF()
  </code></pre>
  
  <p>need a server capable of understanding the modified UTF-8</p>
  
  <hr>
  
  <pre><code>byte[] buf = body.getBytes("UTF-8");
  dos.write(buf, 0, buf.length);
  </code></pre>
  
  <h2>strings work but no special chars</h2>
  
  <p>update: Got it working with StringEntity(* string, "UTF-8") then parse the result to a byte[] and write it with dos.write(byte[])!</p>
  
  <p>--</p>