title: How to switch from HttpURLConnection to HttpClient
body: <p>this is my first question, so please, bear with me.</p>
  
  <p>I have a Swing application, which gets data in a for of XML from a server through HttpURLConnection. Now I'm trying to create a constant request-respond connection with the server, to check if there are any updates for the application (as the checking has to be done regularly and often (every second or so)).</p>
  
  <p>In some question's comment I read that it would be better to use Apache HttpClient instead of HttpURLConnection to maintain a live connection, but I can't find any good example how to go from my current code to the one with HttpClient. Specifically, what to use instead of HttpURLConnection.setRequestProperty() and HttpURLConnection.getOutputStream()?</p>
  
  <pre><code>Document request = new Document(xmlElement);
  Document response = new Document();
  
  String server = getServerURL(datasetName);
  try {
    URL url = new URL(server);
    try {
      HttpURLConnection connection = (HttpURLConnection)url.openConnection();
      connection.setRequestProperty("Content-Type","application/xml; charset=ISO-8859-1");
      connection.setDoOutput(true);
      connection.setDoInput(true);
      connection.setRequestMethod("POST");
      OutputStream output = connection.getOutputStream();
  
      XMLOutputter serializer = new XMLOutputter();
      serializer.output(request, output);
  
      output.flush();
      output.close();
  
      InputStream input = connection.getInputStream();
      String tempString = ErrOut.printToString(input);
  
      SAXBuilder parser = new SAXBuilder();
      try {
        response = parser.build(new StringReader(tempString));
      }
      catch (JDOMException ex) { ... }
      input.close();
      connection.disconnect();
    }
    catch (IOException ex) { ... }
  }
  catch (MalformedURLException ex) { ... }
  </code></pre>