title: HTTP POST request with JSON String in JAVA is not working
body: <p>I have the below small code to get the json reply from service providers, what i have tried is that to post a http post request but it always throws </p>
  
  <pre><code>java.net.UnknownHostException: directory.qantasloyalty.com
      at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
      at java.net.Socket.connect(Socket.java:519)
      at java.net.Socket.connect(Socket.java:469)
      at sun.net.NetworkClient.doConnect(NetworkClient.java:157)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:382)
      at sun.net.www.http.HttpClient.openServer(HttpClient.java:509)
      at sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(HttpsClient.java:278)
      at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:335)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:176)
      at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:769)
      at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:162)
      at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:861)
      at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
      at Test.Httptestpost.sendPost(Httptestpost.java:124)
      at Test.Httptestpost.main(Httptestpost.java:32)
  </code></pre>
  
  <p>PLease find my code below,</p>
  
  <pre><code>private void sendPost() {
      System.getProperties().put("http.proxySet", "true");
      System.getProperties().put("http.proxyHost", "proxyurl");
      System.getProperties().put("http.proxyPort", "8080");
      System.getProperties().put("http.proxyUser", "username");
      System.getProperties().put("http.proxyPassword", "pwd");
      System.getProperties().put("http.nonProxyHosts", "localhost|127.0.0.1");
  
      String url = "httpsurlhere";
      URL obj = null;
      try {
          obj = new URL(url);
      } catch (MalformedURLException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      HttpsURLConnection con = null;
      try {
          con = (HttpsURLConnection) obj.openConnection();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      //add reuqest header
      try {
          con.setRequestMethod("POST");
      } catch (ProtocolException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      //con.setRequestProperty("User-Agent", USER_AGENT);
      //con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
      con.setRequestProperty("Content-Type", "application/json;UTF-8");
  
      String urlParameters = "username=demouser&amp;password=aDemoPassword";
      String input = "{\"username\":\"demouser\",\"password\":\"aDemoPassword\"}";
      System.out.println("input"+input);
      System.out.println("url"+con.getURL());
      System.out.println("req prop :"+con.getRequestProperties());
      // Send post request
      con.setDoOutput(true);
      DataOutputStream wr;
      try {
          wr = new DataOutputStream(con.getOutputStream());
  
          wr.writeBytes(input);
  
      wr.flush();
      wr.close();
  
  
      int responseCode = con.getResponseCode();
      System.out.println("\nSending 'POST' request to URL : " + url);
      System.out.println("Post parameters : " + urlParameters);
      System.out.println("Response Code : " + responseCode);
  
      BufferedReader in = new BufferedReader(
              new InputStreamReader(con.getInputStream()));
      String inputLine;
      StringBuffer response = new StringBuffer();
  
      while ((inputLine = in.readLine()) != null) {
          response.append(inputLine);
      }
      in.close();
  
      //print result
      System.out.println(response.toString());
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  </code></pre>
  
  <p>Can someone please help me to route the cause</p>
  
  <p><strong>For security purpose I have not shared the exact proxy URL and http post webservice URl also here</strong> </p>