title: How to send Post Data to https server via HttpsURLConnection
body: <p>I saw a form (<a href="https://aptransport.in/CFSTONLINE/Reports/VehicleRegistrationSearch.aspx" rel="nofollow">https://aptransport.in/CFSTONLINE/Reports/VehicleRegistrationSearch.aspx</a>) in web, if i give Select Search Element: as Registration No and Enter Search Element: as AP31BF2942 ,and if i click on get data button, then i am getting my vehicle Details.<br>
  I want to do this in HttpsURLConnection.<br>
   I have seen parameter names as ctl00$OnlineContent$ddlInput and  ctl00$OnlineContent$txtInput in the source of url.  </p>
  
  <p>But i am unable to get required data.Please check the url</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.DataOutputStream;
  import java.io.InputStreamReader;
  import java.net.HttpURLConnection;
  import java.net.URL;
  
  import javax.net.ssl.HttpsURLConnection;
  
  public class TestAPHttp {
  
  private final String USER_AGENT = "Mozilla/5.0";
  
  public static void main(String[] args) throws Exception {
  
      TestAPHttp http = new TestAPHttp();
  
  
      System.out.println("\nTesting  - Send Http POST request");
      http.sendPost();
  
  }
  
  
  
  // HTTP POST request
  private void sendPost() throws Exception {
  
      String url = "https://aptransport.in/CFSTONLINE/Reports/VehicleRegistrationSearch.aspx";
      URL obj = new URL(url);
      HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();
  
      //add reuqest header
      con.setRequestMethod("POST");
      con.setRequestProperty("User-Agent", USER_AGENT);
      con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
  
      String urlParameters = "ctl00$OnlineContent$ddlInput=R&amp;ctl00$OnlineContent$txtInput=AP31BF2942";
  
      // Send post request
      con.setDoOutput(true);
      DataOutputStream wr = new DataOutputStream(con.getOutputStream());
      wr.writeBytes(urlParameters);
      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());
  
  }
  
  }
  </code></pre>