title: Sending Multipart Form Data in Android
body: <p>I have used the below code (taken from SO) to post some data to a PHP script:</p>
  
  <pre><code>HttpClient httpClient = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost(Web.API_PREFIX_GENERAL + "ajax/process.AL.php");
  
  MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
  reqEntity.addPart("mail", new StringBody("abcd@abcd.com"));
  reqEntity.addPart("remote", new StringBody("1"));
  reqEntity.addPart("altitle", new StringBody("GHI"));
  reqEntity.addPart("aldesc", new StringBody("JKL"));
  reqEntity.addPart("t", new StringBody("N"));
  reqEntity.addPart("lat", new StringBody(lati));
  reqEntity.addPart("long", new StringBody(longi));
  reqEntity.addPart("p", new StringBody("all"));
  
  httpPost.setEntity(reqEntity);
  httpClient.execute(httpPost);
  </code></pre>
  
  <p><strong>...And this does not produce anything. No error, but nothing gets posted either.</strong></p>
  
  <p>However, if I use something like below and have no parts added to <code>reqEntity</code>,</p>
  
  <pre><code>String url = Web.API_PREFIX_GENERAL + "ajax/process.AL.php?mail=abcd@abcd.com&amp;remote=1&amp;altitle=GHI" +
                      "&amp;aldesc=JKL&amp;t=N&amp;lat=" + lati + "&amp;long=" + longi + "&amp;p=all";
  
  HttpClient httpClient = new DefaultHttpClient();
  HttpPost httpPost = new HttpPost(url);
  
  MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
  
  httpPost.setEntity(reqEntity);
  httpClient.execute(httpPost);
  </code></pre>
  
  <p><strong>...this works</strong></p>
  
  <p>I have all the required Apache libraries set up also. So any idea why this is?</p>
  
  <p>I need to use <code>MultipartEntity</code> because I'll also have to post an image later.</p>
  
  <p>Thanks.</p>