Just trying to send a POST request with this simple code
URL urlObj = new URL("http://localhost/myApp");
HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/json");
con.setDoOutput(true);
DataOutputStream dataOutputStream = new DataOutputStream(con.getOutputStream());
dataOutputStream.writeBytes("test data");
dataOutputStream.flush();
dataOutputStream.close();
The request above is not being sent UNTIL I add the additional lines
int responseCode = con.getResponseCode();
System.out.println("Response Code : " + responseCode);
Am I missing something? why it's not sending?
Tried to breakpoint on the server taking the request but nothing is reaching it at all