2

I'm debugging some code that was written using java.net.HttpURLConnection. I'd like to set a property to enable logging of HTTP Request and Response headers as is possible in the Apache HTTP Components library with the org.apache.http.headers category.

Is this possible with HttpURLConnection? Do I need to breakout Charles Proxy or Wireshark?

1

1 Answer 1

4

According to Sun's HttpURLConnection source there is some logging support via JUL.

This would require setting up java.util.logging with sun.net.www.protocol.http.HttpURLConnection.level=ALL.

See http://www.rgagnon.com/javadetails/java-debug-HttpURLConnection-problem.html for example.

There is also system property -Djavax.net.debug=all. But it's mainly useful for SSL debugging.

BTW, Wireshark is also a rather easy option.

Sign up to request clarification or add additional context in comments.

1 Comment

This gave me exactly what I needed. The source is always the source of truth so I should've looked there first but this seems like nice functionality that I'm not sure why it didn't make it to the Javadoc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.