title: Creating a multipart/form-data entity with Apache HTTP client
body: <p>I'm trying to create an HTTP entity for a POST request that looks like the one listed as part of the contextIO API listed here: </p>
  
  <p><a href="http://context.io/docs/2.0/accounts/messages#post">http://context.io/docs/2.0/accounts/messages#post</a></p>
  
  <p>From their docs, they give the following example:</p>
  
  <pre><code>POST /2.0/accounts/4f01234567890abcdef09876/messages/ HTTP/1.1
  Host: api.context.io
  Accept: */*
  Authorization: OAuth oauth_consumer_key="abcdef1234",oauth_version="1.0",oauth_timestamp="1327695986",oauth_nonce="6dPrHNDrx5hzfHkn",oauth_signature_method="HMAC-SHA1",oauth_signature="MFOyvf5Ykcsn7une48kGW0Aharw%3D"
  Content-Type: multipart/form-data; boundary=------someRandomBoundary
  Content-Length: 1917
  
  --------someRandomBoundary
  Content-Disposition: form-data; name="dst_folder"
  
  testFolder
  --------someRandomBoundary
  Content-Disposition: form-data; name="message"; filename="message.eml"
  Content-Type: message/rfc822
  
  Delivered-To: jim@bob.com
  Received: by 101.42.118.54 with SMTP id hp10cs194007icb;
          Thu, 13 Jan 2012 15:02:20 -0700 (PDT)
  Return-Path: &lt;blahblahblah@someisp.com&gt;
  Received: from [192.168.1.5] (71-211-196-225.hlrn.bob.com. [71.211.196.225])
          by mx.bob.com with ESMTPS id u41si888834ybu.20.2011.10.13.14.54.54
          (version=TLSv1/SSLv3 cipher=OTHER);
          Thu, 13 Jan 2012 15:02:20 -0700 (PDT)
  Received: from mail-gx0-f174.someisp.com (mail-gx0-f174.someisp.com [109.45.123.134])
          by mx.someisp.com with ESMTPS id u41si888834ybu.20.2011.10.13.14.54.54
          (version=TLSv1/SSLv3 cipher=OTHER);
          Thu, 13 Jan 2012 14:54:53 -0700 (PDT)
  Message-ID: &lt;2E973E2A.3150305@bob.com&gt;
  Date: Thu, 13 Jan 2012 15:54:50 -0600
  From: Dave Davidson &lt;blahblahblah@someisp.com&gt;
  User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13
  MIME-Version: 1.0
  To: Jim Bob &lt;jim@bob.com&gt;
  Subject: Just sending out a test message
  Content-Type: multipart/alternative;
   boundary="------------030009050309030308020807"
  
  This is a multi-part message in MIME format.
  --------------030009050309030308020807
  Content-Type: text/plain; charset=UTF-8
  Content-Transfer-Encoding: 7bit
  
  Yo! This is a test multi-part message.
  
  
  --------------030009050309030308020807
  Content-Type: text/html; charset=UTF-8
  Content-Transfer-Encoding: 7bit
  
  &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta content="text/html; charset=UTF-8" http-equiv="Content-Type"&gt;
    &lt;/head&gt;
    &lt;body bgcolor="#ffff00" text="#ff0000"&gt;
      Yo! This is a test multi-part message.&lt;br&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  
  --------------030009050309030308020807--
  
  --------someRandomBoundary--
  </code></pre>
  
  <p>I've tried to do this using:</p>
  
  <pre><code>HttpEntity entity = MultipartEntityBuilder.create()
                      .addBinaryBody("message", messageSource.getBytes(), ContentType.create("message/rfc822"), "message.eml")
                      .addTextBody("dst_folder", label)
                      .addTextBody("dst_source", "0")
                      .build();
  </code></pre>
  
  <p>But I can't seem to wrap the whole thing in a multipart/form-data section. <strong>Any ideas how to create this request using the Apache HTTP Client?</strong></p>