Это поддерживается только с Jsoup 1.8.2 (13 апреля 2015 г.) с помощью нового метода 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", "info@tutorialswindow.com")
.data("file", file.getName(), new FileInputStream(file))
.post();
// ...
В более старых версиях отправка multipart/form-data
запросовне поддерживается.Для этого лучше всего использовать полноценный HTTP-клиент, такой как Apache HttpComponents Client .В конечном итоге вы можете получить ответ клиента HTTP как String
, чтобы можно было передать его методу 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("info@tutorialswindow.com"));
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);
// ...