EN
Java Jsoup - Connection.Request how to set size of response body to bigger one?
13
points
1. Problem description
How do I change the size of Jsoup response?
When I get larger response Jsoup get only 1 MB of document or json.
Code example:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
public class JsoupMaxResponseSizeExample {
public static void main(String[] args) throws IOException {
String url = "http://localhost:8080/get-all-users";
Document document = Jsoup.connect(url)
.get();
System.out.println(document);
System.out.println(document.toString().length());
}
}
2. Solution
Fix is to use .maxBodySize(0)
Jsoup.connect("http://localhost:8080/get-all-users")
// FIX - this line set max response size without limits
// the only limit is your machine
.maxBodySize(0)
Merged questions Full code example:
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import java.io.IOException;
public class JsoupMaxResponseSizeExampleFix {
public static void main(String[] args) throws IOException {
String url = "http://localhost:8080/get-all-users";
Document document = Jsoup.connect(url)
// FIX: A max size of zero is treated as an infinite amount
// (bounded only by your patience and the memory available
// on your machine).
.maxBodySize(0)
.get();
System.out.println(document);
System.out.println(document.toString().length());
}
}