Jsoup http logging

2019-06-25 00:51发布

问题:

Is there a way to log the http request and response? Let's assume the below request

Connection.Response res = Jsoup.connect("LOGIN_URL_HERE")
            .data("user", "USER", "pass", "PASS")
            .method(Connection.Method.POST)
            .execute();

How can I log the http request and response? Please mind that I want the HTTP and not just the HTML that will be parsed.

回答1:

By default jsoup uses a implementation of java.net.HttpURLConnection So I suppose you need to turn on logging for that implementation (probably: sun.net.www.protocol.http.HttpURLConnection) or for java net.

There is a system property that will enable logging for java net utils

-Djavax.net.debug=all