title: HttpUrlConnect not sending a post request as part of a thread
body: <p>I'm trying to send a http post request as part of a concurrent thread to an application launch.  </p>
  
  <p>The code below shows the current code I have now.  I tried using the code from Baeldung and similar tutorial sites but I can't seem to get this working.</p>
  
  <pre class="lang-java prettyprint-override"><code> public static void main(String[] args) throws Exception {
      HttpURLConnection con = (HttpURLConnection) new URL("http://localhost:5000/").openConnection();
      con.setRequestMethod("POST");
      con.setRequestProperty("Content-Type", "application/json; utf-8");
      con.setDoOutput(true);
      String jsonInputString = "{\"status\": \"UP\"}";
      OutputStream os = con.getOutputStream();
  
      //random code here not involved with this quesiton
  
      new Thread(new Runnable() {
        public void run() {
          while (true) {
            try {
  
              os.write(jsonInputString.getBytes());
              os.flush();
          }
            catch (Exception exception) {
              System.out.println("Its not working");
            }
          }
  
        }
      }).start();
      launch(args);
  </code></pre>
  
  <p>When I go to type in localhost:5000 in a browser it says it can't connect.</p>