title: How do I send a POST request in Java?
body: <p>When I send request from JSP I use this code</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form method="post"  action="http://translate.intelsoft.az" id="tform" name="ftext"&gt;
  &lt;input class="gogo1"  value="a" name="l" id="l1" /&gt; &lt;div class="il"&gt;
  &lt;p&gt;Rusca&lt;/p&gt;
  &lt;textarea class="ilkin1" name="t" id="t1" &gt;
  выыававыавыавыавфыа
  выыававыавыавыавфыа
  выыававыавыавыавфыа
  выыававыавыавыавфыа&lt;/textarea&gt;
  &lt;div&gt;&lt;input class="gogo" type="submit" value="Tərcümə1" name="b1" /&gt;&lt;/div&gt;&lt;/div&gt;    &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>and the response is correct, so that I see my parameter's value. But when I send from Java I get no correct response. I think that the parameters are not sent correctly. Here's my Java code:</p>
  
  <pre><code>String urlParameters = "t=выыававыавыавыавфыа&amp;l=a";
  String request = "http://translate.intelsoft.az";
  URL url = null;
  try {
      url = new URL(request);
  } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } 
  HttpURLConnection connection = null;
  try {
      connection = (HttpURLConnection) url.openConnection();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }           
  connection.setDoOutput(true);
  connection.setDoInput(true);
  connection.setInstanceFollowRedirects(false); 
  try {
      connection.setRequestMethod("POST");
  } catch (ProtocolException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  } 
  connection.setRequestProperty("Content-Type", "text/html"); 
  connection.setRequestProperty("charset", "utf-8");
  connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
  connection.setUseCaches (false);
  
  DataOutputStream wr;
  try {
      wr = new DataOutputStream(connection.getOutputStream ());
      wr.writeBytes(urlParameters);
      wr.flush();
  
      BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
      String line;
      while ((line = rd.readLine()) != null) {
          System.out.println(line);
      }
      wr.close();
  
  
  
  
  
      connection.disconnect();
  } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
  }
  </code></pre>
  
  <p>What is wrong here?</p>