Android HttpURLConnection write post data
<p>I'm trying to send post data through HttpURLConnection and it doesn't seem to send the post data.</p>

<p>I'm able to output the data through Toast immediately before trying to send a POST request, but when I check on the server side it makes the connects to the PHP file, but the POST data is empty.</p>

<p>So, I know the data exists in the jsonObject.
    I also know it makes it to the try catch statement, but when I connect it's not being sent or received properly.</p>

<pre><code>try {
        URL url = new URL(emailURL);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();

        conn.setDoOutput(true);

        conn.setRequestMethod( "POST" );
        conn.setRequestProperty( "Content-Type", "application/json");
        conn.setRequestProperty( "charset", "utf-8");
        conn.setRequestProperty( "Content-Length", Integer.toString( jsonObject.toString().length() ));
        conn.setUseCaches( false );

        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

        wr.write(jsonObject.toString());

          wr.close();

        BufferedReader reader = null;
        reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        StringBuilder sb = new StringBuilder();
        String line = null;

        // Read Server Response
        while ((line = reader.readLine()) != null) {
            // Append server response in string
            sb.append(line + "\n");
        }

        String text = "";
        text = sb.toString();



    } catch (Exception e) {

        throw new RuntimeException(e);
    }
</code></pre>