6

I have some java code both new (using Apache commons http libraries) and old (strictly using java 1.4 API) and am trying to rewrite the old code using the newer apache commons libraries. However, it isn't working and I'm struggling to find out why. The requests are being sent, but my newer code times out on the receiving server which I don't have access to. Since the old code works, I must have mucked up the http request. It would be very useful to use some sort of HTTP traffic sniffer to examine exactly what is being sent so I can see what differences there are.

I've downloaded a few http sniffers from the web (this one and that one) but neither capture any of the http data being sent by my java code (but they do work when I send random requests from a browser). Any ideas out there on how I can get my hands on this data?

Chris Knight
  • 24,333
  • 24
  • 88
  • 134

4 Answers4

8

Use wireshark.

It's great, free, open-source, cross-platform, and can highlight different network layers, and it's not running from some dubious website that looks like SEO spam.

Snort is another good one, but it's more geared toward intrusion detection and automated responses to that. Still, it has a great sniffer.

Sdaz MacSkibbons
  • 27,668
  • 7
  • 32
  • 34
  • 2
    Perfect thanks. Feels a bit like having an entire hardware store at my dispoal when all I need is a screwdriver, but hey, job done! – Chris Knight Feb 01 '11 at 11:53
  • Friendly informational tip, you will have to do some futzing around to get wireshark to capture [localhost](http://wiki.wireshark.org/CaptureSetup/Loopback) traffic and it is quite difficult to capture windows localhost traffic. – hooknc Oct 07 '14 at 22:55
3

Typically I find that packet sniffing is too low level for troubleshooting HTTP. Try a reverse proxy; personally I like Charles as it works the same in Windows, Mac OS X and Linux; Fiddler is a popular on Windows.

Uriah Carpenter
  • 6,656
  • 32
  • 28
  • Thanks for the suggestion, but (and I may be about to get in over my head here) my java program doesn't interact with the web, it simply communicates to a local server via http and so Fiddler doesn't capture my requests. – Chris Knight Feb 01 '11 at 11:58
  • Charles works great for these types of situations. To configure Commons HttpClient to use a local proxy server: `client.getHostConfiguration().setProxy("localhost", 8888)`. – Uriah Carpenter Feb 01 '11 at 16:27
0

If you try to sniff your loopback(127.0.0.1) - thats bit complicated and you should install special driver for that.
I'd suggest you to send request to "fake" server and than sniff it.
u can sniff with "WireShark" or "burpSuite" (if u can configure ur program that go through proxy server).
gl.

Ratinho
  • 298
  • 1
  • 6
0

you can specify SOCKS Proxy. normally Java uses SocksSocketImpl - i.e. it supports automatically SOCKS proxies.

Any other sniffer will do as well

bestsss
  • 11,796
  • 3
  • 53
  • 63