title: apache HttpClient, upload a file via form: use StringBody instead of FileBody
body: <p>A web server expects a file to be uploaded via an html form.<br/></p>
  
  <p>This is the way how i construct the MultipartEntity, that already works:</p>
  
  <pre><code>FileBody filePart = new FileBody(new File("emptyFile.txt"), "text/plain");
  FormBodyPart fbp = new FormBodyPart("UploadService", filePart);
  MultipartEntity mpe = new MultipartEntity();  
  mpe.addPart(fbp);
  </code></pre>
  
  <p>The fact is that i have my data in memory, so i don't like the idea of saving it to disk, and so I've tried to replace</p>
  
  <pre><code>FileBody filePart = new FileBody(new File("emptyFile.txt"), "text/plain");
  </code></pre>
  
  <p>with </p>
  
  <pre><code>StringBody filePart = new StringBody("");    
  </code></pre>
  
  <p>But the second way doesn't work, the server returns a HTTP 500 exception; logging the data on the wire, i noticed that the only difference is as follows:</p>
  
  <p>HTTP POST trace when FileBody has been used:</p>
  
  <pre><code>...
  Content-Disposition: form-data; name="UploadService"; filename="emptyFile.txt"
  ...
  </code></pre>
  
  <p>HTTP POST trace when StringBody has been used:</p>
  
  <pre><code>...
  Content-Disposition: form-data; name="UploadService"
  ...
  </code></pre>
  
  <p>That is, in the FileBody upload, it is specified a "filename" that is not specified in the StringBody upload.
  How can i fix this?</p>