これは、新しいdata(String, String, InputStream)
メソッドを使用して1.8.2(Apr15、2015年4月13日) からのみサポートされます。古いバージョンでは
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();
// ...
、multipart/form-data
要求を送信することはサポートされていません。最も良いのは、Apache HttpComponents Clientのような完全なHTTPクライアントを使用することです。最終的に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("[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);
// ...