I am trying to send a POST request to my server. I have successfully send a POST request using Postman app so I assume I have messed it up somewhere in my Android app. The code that i used is described here sample code
Boolean makePostServiceCall(String postUrl, String json){
Log.d(TAG, "makePostServiceCall: starts");
try{
URL url = new URL(postUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestMethod("POST");
conn.connect();
//Write
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(json);
writer.close();
os.close();
} catch (MalformedURLException e) {
e.printStackTrace();
return false;
} catch (ProtocolException e) {
Log.e(TAG, "ProtocolException: " + e.getMessage());
return false;
} catch (IOException e) {
Log.e(TAG, "IOException: " + e.getMessage());
return false;
}
return true;
}
The parameter json looks like this D/PostOrder: doInBackground: json string is: {"tableID":"2","price":"22","payment":"cash","quantity":"1","products":[{"ID":"1","quantity":"1"}]}
Any help will be greately appreciated