I use this tutorial to use HttpRULConnection to post info to server. Following is my code:
    String urlParameters = "username=" + username + "®id=" + uuid;
    byte[] postData = urlParameters.getBytes( StandardCharsets.UTF_8 );
    try {
        URL url = new URL(server_uri);
        try {
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setDoOutput(true);
            conn.setDoInput(true);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("X-latitude", "40.7439905");
            conn.setRequestProperty("X-longitude", "-74.0323626");
            conn.setRequestProperty("charset", "utf-8");
            conn.setRequestProperty( "Content-Length", Integer.toString( postData.length ));
            conn.setUseCaches(false);
            int responseCode = conn.getResponseCode();
            Log.d("responseCode", responseCode + "");
            //send register request
            OutputStream wr = conn.getOutputStream();
            wr.write(postData);
            wr.flush();
            wr.close();
            //get response
            .........
            Log.d("registration_id", registerResponse.registration_id+"");
        } catch (IOException e) {
            e.printStackTrace();
        }
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
However, the LogCat said:
content-length promised 54 bytes, but received 0 .
It means that the parameters did not post successfully.
And in my server, it also display:
username=null, uuid=null
thanks in advance.
 
     
    