title: How to send a XML request with httpclient and receive a file? (Java)
body: <p>I need to send a XML request to a webservice which was not developed using SOAP protocoal. The webservice only works with pure XML request/answer, so there is not WSDL. The webservice will answer with a gzip file which I have to download. Can anyone help me please? I started with the code below. Thanks!</p>
  
  <pre><code>import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.StringEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.util.EntityUtils;
  
  public class Teste {
  
  public static void main(String[] args)
  {
      boolean success = XMLDataPost();
      System.out.println(success);
  }
  
  private static boolean  XMLDataPost(){
  
      boolean success = false;
      HttpClient httpclient = new DefaultHttpClient();
  
      try {
  
          HttpPost httpPost = new HttpPost("http://webservice.blablabla.com.br");
  
          StringEntity reqEntity = new StringEntity("&lt;RequestVeiculo&gt;&lt;login&gt;02566288000191&lt;/login&gt;&lt;senha&gt;159828&lt;/senha&gt;&lt;/RequestVeiculo&gt;");
          reqEntity.setContentType("text/xml");
          reqEntity.setChunked(true);
  
          httpPost.setEntity(reqEntity);
  
          HttpResponse response = httpclient.execute(httpPost);
          HttpEntity resEntity = response.getEntity();
  
          if(response.getStatusLine().getStatusCode() == 200){
              success = true;
          }
          if (resEntity != null) {
              System.out.println("Tamanho: " + resEntity.getContentLength());
              System.out.println("Chunked?: " + resEntity.isChunked());
          }
          EntityUtils.consume(resEntity);
      } 
      catch (Exception e) {
          System.out.println(e);
      }
      finally {
          httpclient.getConnectionManager().shutdown();
      }
      return success;
  }
  }
  </code></pre>