title: Send Xml string through POST method in java
body: <p>I want to pass an xml string through POST method to an URL. </p>
  
  <p>I tried below snippet but it doesn't return anything</p>
  
  <pre><code>disableCertificateValidation();
  String url = "https://..url";   //https
  
  Properties sysProps = System.getProperties();
  sysProps.put("proxySet", "true");
  sysProps.put("proxyHost", "1.2.3.4");
  sysProps.put("proxyPort", "80");
  
  Authenticator authenticator = new Authenticator() {
      public PasswordAuthentication getPasswordAuthentication() {
          return (new PasswordAuthentication("userid",
                  "password".toCharArray()));
      }
  };
  Authenticator.setDefault(authenticator);
  
  
   String xml = ---xml string;            
  
  
  URL urll;
  HttpURLConnection connection = null;
  try {
      // Create connection
      urll = new URL(url);
      connection = (HttpURLConnection) urll.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type",
              "application/x-www-form-urlencoded");
  
      connection.setRequestProperty("Content-Length", ""
              + Integer.toString(xml.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(xml);
      wr.flush();
      wr.close();
  
      // Get Response
      InputStream is = connection.getInputStream();
      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
      String line;
      StringBuffer response = new StringBuffer();
      while ((line = rd.readLine()) != null) {
          response.append(line);
          response.append('\r');
      }
      rd.close();
      System.out.println("response.toString();"+response.toString());
  
  
  } catch (Exception e) {
  
      e.printStackTrace();
  
  
  } finally {
  
      if (connection != null) {
          connection.disconnect();
      }
  }
  </code></pre>
  
  <p>But when I try to post it through jsp I get the proper response from the url.</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  function set(){
          document.getElementById("eXml").value=---xml string
      document.getElementById("textt").value=document.getElementById("eXml").value;
      alert(document.getElementById("eXml").value);
      document.getElementById("myForm").action="https---" //https url;
          document.getElementById("myForm").submit();
  }
  &lt;/script&gt;
  &lt;body&gt;
  &lt;form method="POST" id="myForm"&gt;
  &lt;input type="submit" name="send" onclick="set()"&gt;
  &lt;input type="text" id="textt" value='test'&gt;
  &lt;input type="hidden" name="eXml" id="eXml"&gt; 
  </code></pre>