Esto solo se admite desde Jsoup 1.8.2 (13 de abril de 2015) mediante el nuevo método data(String, String, InputStream)
.
String url = "http://www......com/....php";
File file = new File("/path/to/file.ext");
Document document = Jsoup.connect(url)
.data("user", "user")
.data("password", "12345")
.data("email", "[email protected]")
.data("file", file.getName(), new FileInputStream(file))
.post();
// ...
En versiones anteriores, el envío de solicitudes multipart/form-data
no es compatible. Su mejor opción es utilizar un cliente HTTP completo para esto, como Apache HttpComponents Client. En última instancia, puede obtener la respuesta del cliente HTTP como String
para que pueda alimentarlo al método Jsoup#parse()
.
String url = "http://www......com/....php";
File file = new File("/path/to/file.ext");
MultipartEntity entity = new MultipartEntity();
entity.addPart("user", new StringBody("user"));
entity.addPart("password", new StringBody("12345"));
entity.addPart("email", new StringBody("[email protected]"));
entity.addPart("file", new InputStreamBody(new FileInputStream(file), file.getName()));
HttpPost post = new HttpPost(url);
post.setEntity(entity);
HttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
String html = EntityUtils.toString(response.getEntity());
Document document = Jsoup.parse(html, url);
// ...