0

My application is performing numerous HttpWebRequests, and some of them fail occasionally. I would like to dump the bytes leaving my PC whenever I perform a request as well as the bytes arriving as a response.

Is it possible to do this from within my code easily?

I'd only like to use something like Wireshark as a last resort if no other method is available, as I'd like such dumping to be available on the clients' machines without having to install WinPcap and stuff.

Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
  • It's amazing how hard such simple things are when you're using Windows. Over-engineered WebRequest class has no way of seeing the request body??? Even Wireshark is impossible on localhost because Windows has no loopback interface. – Joe Koberg Sep 23 '12 at 16:07
  • @JoeKoberg haters gonna hate... but so that you don't look quite that lame, [here's an _actual_ crapness](http://stackoverflow.com/questions/3561545) in Windows itself (as opposed to some random API) that you can use to show why Windows is so crap. – Roman Starkov Sep 24 '12 at 22:54

3 Answers3

1

Check out Fidller2 -- yeah it is installing something, but it's not anywhere near as involved as wireshark and it will give you much more useful information. Including being able to dump the streams into re-playable series.

Wyatt Barnett
  • 15,573
  • 3
  • 34
  • 53
  • This doesn't really answer the question but was very helpful nevertheless. For the record, I found no way of doing exactly what the question asks. – Roman Starkov Oct 03 '09 at 17:47
0

There is Microsoft's NetMon or as you said a WinPCap based product like Wireshark. Just like Wireshark, it can be overkill for just HTTP.

As the other post said, there is Fiddler2 is a lot easy to use for debugging HTTP. Also it is useful in debugging HTTPS where NetMon/Wireshark is of no use...

Shane Powell
  • 13,698
  • 2
  • 49
  • 61
0

What I'm doing now is wrapping HttpWebRequest into a class which just dumps all the response headers and body into a specified file. Same for the request, though it's a bit clumsy with POST requests.

The worst thing about this is that I have to change all code that uses HttpWebRequest to use this new wrapper class, but it's not too bad.

Roman Starkov
  • 59,298
  • 38
  • 251
  • 324
  • Now that it's been a couple of months, the wrapping solution made a bunch of other things easier too, so overall I think this was the right decision for my particular use case. – Roman Starkov Aug 24 '09 at 11:11
  • throw us a bone and at least mention what method needs to be overridden to get the output??? – Joe Koberg Sep 23 '12 at 16:04
  • @JoeKoberg The wrapper does not derive from `HttpWebRequest`, so nothing to override. It just logs whatever information I can pull out of the request/response. – Roman Starkov Sep 24 '12 at 22:36