It\'s my first time sending multipart requests and after digging here, I got even more confused so any help regarding the \"correct\" way will be very appriciated.
I
The sample HTML form:
Java code for submiting the multipart form:
MultipartEntityBuilder mb = MultipartEntityBuilder.create();//org.apache.http.entity.mime
mb.addTextBody("foo", "bar");
mb.addBinaryBody("bin", new File("testFilePath"));
org.apache.http.HttpEntity e = mb.build();
URLConnection conn = new URL("http://127.0.0.1:8080/app").openConnection();
conn.setDoOutput(true);
conn.addRequestProperty(e.getContentType().getName(), e.getContentType().getValue());//header "Content-Type"...
conn.addRequestProperty("Content-Length", String.valueOf(e.getContentLength()));
OutputStream fout = conn.getOutputStream();
e.writeTo(fout);//write multi part data...
fout.close();
conn.getInputStream().close();//output of remote url