EN
Java Jsoup - Connection.Request how to set size of response body to bigger one?
13 points
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:
xxxxxxxxxx
1
import org.jsoup.Jsoup;
2
import org.jsoup.nodes.Document;
3
4
import java.io.IOException;
5
6
public class JsoupMaxResponseSizeExample {
7
8
public static void main(String[] args) throws IOException {
9
10
String url = "http://localhost:8080/get-all-users";
11
Document document = Jsoup.connect(url)
12
.get();
13
14
System.out.println(document);
15
System.out.println(document.toString().length());
16
}
17
}
Fix is to use .maxBodySize(0)
xxxxxxxxxx
1
Jsoup.connect("http://localhost:8080/get-all-users")
2
// FIX - this line set max response size without limits
3
// the only limit is your machine
4
.maxBodySize(0)
Merged questions Full code example:
xxxxxxxxxx
1
import org.jsoup.Jsoup;
2
import org.jsoup.nodes.Document;
3
4
import java.io.IOException;
5
6
public class JsoupMaxResponseSizeExampleFix {
7
8
public static void main(String[] args) throws IOException {
9
10
String url = "http://localhost:8080/get-all-users";
11
Document document = Jsoup.connect(url)
12
13
// FIX: A max size of zero is treated as an infinite amount
14
// (bounded only by your patience and the memory available
15
// on your machine).
16
.maxBodySize(0)
17
18
.get();
19
20
System.out.println(document);
21
System.out.println(document.toString().length());
22
}
23
}