form parameters, file uploads and custom body entities Using UniRest

Form parameters

Unirest.post("http://httpbin.org/post")  .field("last", "Polo")  .asJson()

File Uploads

Creating multipart requests with Java is trivial, simply pass along a File or an InputStream Object as a field:

HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")  .header("accept", "application/json")  .field("parameter", "value")  .field("file", new File("/tmp/file"))  .asJson();

Custom Entity Body

HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post")  .header("accept", "application/json")  .body("{\"parameter\":\"value\", \"foo\":\"bar\"}")  .asJson();