Class MultiPartRequestContent

All Implemented Interfaces:
Closeable, AutoCloseable, Request.Content, Content.Source

public class MultiPartRequestContent extends MultiPartFormData.ContentSource implements Request.Content

A Request.Content for form uploads with the "multipart/form-data" content type.

Example usage:

 MultiPartRequestContent multiPart = new MultiPartRequestContent();
 multiPart.addPart(new MultiPart.ContentSourcePart("field", null, HttpFields.EMPTY, new StringRequestContent("foo")));
 multiPart.addPart(new MultiPart.PathPart("icon", "img.png", HttpFields.EMPTY, Path.of("/tmp/img.png")));
 multiPart.close();
 ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
         .method(HttpMethod.POST)
         .body(multiPart)
         .send();
 

The above example would be the equivalent of submitting this form:


 <form method="POST" enctype="multipart/form-data"  accept-charset="UTF-8">
     <input type="text" name="field" value="foo" />
     <input type="file" name="icon" />
 </form>
 
  • Constructor Details

    • MultiPartRequestContent

      public MultiPartRequestContent()
    • MultiPartRequestContent

      public MultiPartRequestContent(String boundary)
  • Method Details