How to send post request with x-www-form-urlencoded body
<p><img src="https://i.stack.imgur.com/azap0.png" alt="Request in postman"></p>

<p>How in java, can I send a request with <code>x-www-form-urlencoded header</code>. I don't understand how to send a body with a key-value, like in the above screenshot.</p>

<p>I have tried this code:</p>

<pre><code>String urlParameters =
  cafedra_name+ data_to_send;
URL url;
    HttpURLConnection connection = null;  
    try {
      //Create connection
      url = new URL(targetURL);
      connection = (HttpURLConnection)url.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type", 
           "application/x-www-form-urlencoded");

      connection.setRequestProperty("Content-Length", "" + 
               Integer.toString(urlParameters.getBytes().length));
      connection.setRequestProperty("Content-Language", "en-US");  

      connection.setUseCaches (false);
      connection.setDoInput(true);
      connection.setDoOutput(true);

      //Send request
      DataOutputStream wr = new DataOutputStream (
                  connection.getOutputStream ());
      wr.writeBytes (urlParameters);
      wr.flush ();
      wr.close ();
</code></pre>

<p>But in the response, I don't receive the correct data.</p>