String postData = "Whatever string you want to send to the server";
try {
   URL url = new URL(”http://www.byu.edu/”);
   
   HttpURLConnection connection = (HttpURLConnection)url.openConnection();
   
   connection.setRequestMethod(”POST”);
   connection.setDoOutput(true);

   // Set HTTP request headers, if necessary
   // connection.addRequestProperty(”Accept”, ”text/html”);
   
   connection.connect();

   // Write post data to request body
   OutputStream requestBody = connection.getOutputStream();
   requestBody.write(postData.getBytes());  
   requestBody.close();
   
   if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
      // Get HTTP response headers, if necessary
      // Map<String, List<String>> headers = connection.getHeaderFields();

      // Get response body input stream
      InputStream responseBody = connection.getInputStream();
	  
      // Read response body bytes
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      byte[] buffer = new byte[1024];
      int length = 0;
      while ((length = responseBody.read(buffer)) != -1) {
         baos.write(buffer, 0, length);
      }
	  
      // Convert response body bytes to a string
      String responseBodyData = baos.toString();
	  
      // TODO: Process response body data
      // ...
   }
   else {
      // SERVER RETURNED AN HTTP ERROR
   }
}
catch (IOException e) {
   // IO ERROR
} 
