I am using Jsoup to post a form to a website, the reply is plain text, but the content type isn't known to Jsoup. Therefore I use ignoreContentType(true), so Jsoup won't throw an exception because of the unknown content type. However I can't figure out how to get the raw reply from Jsoup, the text contains some special characters, that Jsoup strips, also Jsoups adds a body and html tag - I don't need that, I just want the raw reply. How to get the raw reply? Thanks!
You could use Response#body()
for this. E.g.
String body = Jsoup.connect(url).execute().body();
Or if you're doing POST
String body = Jsoup.connect(url).method(Method.POST).data(data).execute().body();
You can get the Response
object from Connection
, and it contains the raw byte data. Ignore content type or it will fail on non-text data. If you use body()
it may mangle the response using the default charset.
Connection conn = Jsoup.connect(url).ignoreContentType(true).method(Method.GET);
Connection.Response response = conn.execute();
byte[] raw = response.bodyAsBytes();
// if you want...
Document parsed = response.parse();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With