title: How do i use apache commons HttpPost to send a file and encode parameters for the request?
body: <p>I am currently programming an application that needs to send an http Post request to a server. The request needs to contain particular parameters which in an equivalent GET request would be encoded in the url. However, the body of the http Request needs to be correctly formatted xml which the server will parse. So, as I understand it, the file needs to be added to the request like so:</p>
  
  <pre><code>httpClient = new DefaultHttpClient();
      HttpPost post = new HttpPost("url...");
      if (httpContent != null){
          InputStreamEntity httpStream = new InputStreamEntity(httpContent,-1);
          httpStream.setContentType("text/xml");
          httpStream.setChunked(true);
  
          post.setEntity(httpStream);
      }
  </code></pre>
  
  <p>And parameters need to be added as a name-value pair like this:</p>
  
  <pre><code>List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2);  
  nameValuePairs.add(new BasicNameValuePair("userid", "12312"));  
  nameValuePairs.add(new BasicNameValuePair("sessionid", "234"));  
  post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  </code></pre>
  
  <p>now, I am pretty sure that the httpPost can only have one entity set unless I am misunderstanding it. So, How can I set the parameters and still retain the xml as the http body?</p>
  
  <p>Thanks in advance!</p>