title: Add parameters to Apache HttpPost
body: <p>I'm trying to send a file to a Servlet.
  Along with this file, I also have to send some parameters (i.e. name/id, date and a few others). I'm using HttpClient on client-side and ServerFileUpload on server-side.</p>
  
  <p>This is the client-side code:
  ...</p>
  
  <pre><code>String url = "http://localhost:8080/RicezioneServlet/RicezioneServlet";
  HttpClient httpclient = new DefaultHttpClient();
  HttpPost postMethod = new HttpPost(url);
  MultipartEntity mpe = new MultipartEntity();
  //I'm sending a .zip file
  ContentBody cb = new FileBody(fileToSend,"application/zip");
  mpe.addPart("file", cb);
  postMethod.setEntity(mpe);
  HttpResponse resp = httpclient.execute(postMethod);
  HttpEntity respEntity = resp.getEntity();
  System.out.println(resp.getStatusLine());
  </code></pre>
  
  <p>...</p>
  
  <p>on the server side, we've got:</p>
  
  <pre><code>ServletFileUpload sup = new ServletFileUpload();
  FileItemIterator it = sup.getItemIterator(request);
  FileItemStream item = it.next();
  InputStream ios = item.openStream();
  //read from ios and write to a fileoutputstream.
  </code></pre>
  
  <p>Now, I don't know how to add the aforementioned parameters to the request... I tried to use a StringBody and to add it to the MultiPartEntity, but I get a NullPointerException at: </p>
  
  <pre><code>String author = request.getParameter("author");
  </code></pre>
  
  <p>which means that the parameter isn't seen as a parameter, maybe? </p>
  
  <p>The only was I got it working was setting these parameters as Headers (setHeader and getHeader), but this is not an option.</p>
  
  <p>Any advice? Or maybe can you redirect me to a <b>full</b> example of file+parameter upload?<br>
  Thanks,<br>
  Alex</p>