title: Post files to server from Android - MultipartEntityBuilder - HTTP
body: <p>I am trying to upload some files to my server (via HTTP POST) from an Android app and I have checked many Questions here but can't get it to work. I hope someone can help me out:</p>
  
  <p>I also included some variables in the URL to verify that at least those are reaching the server(GET). </p>
  
  <pre><code>    HttpClient httpClient = new DefaultHttpClient();
      String url="http://XXXXX.com/files/upload.php?flies=yes&amp;eats=no&amp;friend=yes";
      HttpPost httppost = new HttpPost(url);
      httppost.addHeader("Content-Type", "multipart/form-data");
      String content,response="";
      try {
  
          MultipartEntityBuilder builder = MultipartEntityBuilder.create();
          builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
          builder.addTextBody("randomvar", "42");
  
          //add image file
          //String filename="eye.png";
          //InputStream is=mContext.getAssets().open(filename);
          //builder.addBinaryBody("image", is, ContentType.create("image/png"), filename);
  
          //add text XML file
          final File file = new File(mContext.getFilesDir() +"/"+"serverXML.xml");
          FileBody fb = new FileBody(file);
          builder.addPart("file", fb);
          httppost.setEntity(builder.build());
  
  
          response = EntityUtils.toString(httpClient.execute(httppost).getEntity(), "UTF-8");
  
  
          Log.i(TAG, "RESPONSE FROM SERVER: "+response);
      } catch (IOException e) {
          Log.i(TAG, "Exception: "+response);
          e.printStackTrace();
      }
  </code></pre>
  
  <p>This does run and get a response from the server. The following is the vardump of $_GET, $_POST, $_FILES:</p>
  
  <p><img src="https://i.stack.imgur.com/qJsuQ.png" alt="enter image description here"></p>
  
  <p>I would want POST to have the file and variable</p>
  
  <p>In my Eclipse Logcat I see the following after using MultiPartEntityBuilder:</p>
  
  <pre><code>10-06 02:36:57.231: D/dalvikvm(15888): DexOpt: couldn't find static field Lorg/apache/http/message/BasicHeaderValueParser;.INSTANCE
  10-06 02:36:57.241: W/dalvikvm(15888): VFY: unable to resolve static field 5966 (INSTANCE) in Lorg/apache/http/message/BasicHeaderValueParser;
  10-06 02:36:57.241: D/dalvikvm(15888): VFY: replacing opcode 0x62 at 0x001b
  10-06 02:36:57.241: D/dalvikvm(15888): DexOpt: couldn't find static field Lorg/apache/http/message/BasicHeaderValueFormatter;.INSTANCE
  10-06 02:36:57.241: W/dalvikvm(15888): VFY: unable to resolve static field 5960 (INSTANCE) in Lorg/apache/http/message/BasicHeaderValueFormatter;
  </code></pre>
  
  <p>I think I have correctly included all the required libraries:</p>
  
  <p><img src="https://i.stack.imgur.com/JhKQ3.png" alt="enter image description here"></p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I was able to solve this, my solution is the described in my answer below</p>