title: Java http Post request
body: <p>How can i make a request for this format in java:</p>
  
  <p>POST URL http/1.1</p>
  
  <p><strong>Headers:</strong>
  Host ... 
  Accept... 
  ...... More headers
  ......
  <strong>Request body</strong>
  send = ..... some data</p>
  
  <p>I tryied this code with my headers and body, but it doesn't work</p>
  
  <pre><code>String urlParameters  = "send = .....";
  byte[] postData       = urlParameters.getBytes( StandardCharsets.UTF_8 );
  int    postDataLength = postData.length;
  String request        = "http://example.com/index.php";
  URL    url            = new URL( request );
  HttpURLConnection conn= (HttpURLConnection) url.openConnection();           
  conn.setDoOutput( true );
  conn.setInstanceFollowRedirects( false );
  conn.setRequestMethod( "POST" );
  conn.setRequestProperty( "Content-Type", "application/x-www-form-urlencoded"); 
  conn.setRequestProperty( "charset", "utf-8");
  conn.setRequestProperty( "Content-Length", Integer.toString( postDataLength ));
  conn.setUseCaches( false );
  try( DataOutputStream wr = new DataOutputStream( conn.getOutputStream())) {
     wr.write( postData );
  }
  </code></pre>