Languages
[Edit]
EN

Java Jsoup - Connection.Request how to set size of response body to bigger one?

13 points
Created by:
Root-ssh
175500

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());
    }
}

Merged questions

  1. How to fetch large json response with Jsoup?
  2. Jsoup can't download entire document - fix
  3. How do I get full document data with Jsoup connect?
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join