private void sendHTTPData(JSONObject json) {
StringBuilder stringBuilder = new StringBuilder();
try {
URLConnection connection = null;
connection = url.openConnection();
connection.setDoInput(true);
((HttpURLConnection)connection).setRequestMethod("POST");
connection.setRequestProperty("Content-Type", APPLICATION_JSON);
connection.setRequestProperty("Accept", APPLICATION_JSON);
OutputStreamWriter streamWriter = new OutputStreamWriter(connection.getOutputStream());
streamWriter.write(json.toString());
streamWriter.flush();
//Verify Response
if (((HttpURLConnection)connection).getResponseCode() == HttpURLConnection.HTTP_OK){
InputStreamReader streamReader = new InputStreamReader(connection.getInputStream());
BufferedReader bufferedReader = new BufferedReader(streamReader);
String response = null;
while ((response = bufferedReader.readLine()) != null) {
stringBuilder.append(response + "\n");
}
bufferedReader.close();
((HttpURLConnection)connection).getResponseMessage();
System.out.println("Received Response..... " + stringBuilder.toString());
}
} catch (Exception e){
System.out.println(e.getMessage());
} finally {
System.out.println("Disconnecting..... HttpURLConnection");
((HttpURLConnection)connection).disconnect();
}
}