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?

cclark
  • 1,402
  • 3
  • 17
  • 25
  • Possible duplicate of [How to enable wire logging for a java HttpURLConnection traffic?](http://stackoverflow.com/questions/1445919/how-to-enable-wire-logging-for-a-java-httpurlconnection-traffic) – Vadzim Oct 09 '15 at 10:23

1 Answers1

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.

Vadzim
  • 24,954
  • 11
  • 143
  • 151
  • 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. – cclark Sep 07 '12 at 16:33