I know that you all will answer "use a debugging proxy such as Fiddler", but it's not that simple.
Here is my situation: I have code that runs on the server in an ASP.NET page with code (aspx.cs) that (by the way) establishes a connection to another server, captures some things, and then formats it and returns it to browser.
The problem is that the other server is doing the wrong thing, and therefore I want to be able to pass the debug flag to the page (via the query string, for example? Debug = true) so that it prints a completely raw HTTP request that it sends to another server, so that I can see what kind of mistake this is. This code works in several places, so I want to be able to simply pass this flag to a dev, intermediate or production process and just see the request, without having to find out if production servers can talk to some proxy server that exists somewhere, etc.
You might think that it would be easy to do this, right? So I feel like I'm crazy or something, but I looked at the link to HttpWebRequest and its parent class WebRequest and nothing. No. You would think that Microsoft would think about it. The closest thing is that you can access the Headers collection, but when I tried it, it omitted some really important headers, such as “content length”, so it should “lie” to me (I know this is lying, because what I know for the fact that the remote server returns the status 200 - the request is successful, it just returns bad / different / wrong data)
Here is the sample code for the request:
HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.whatever.com"); req.Method = ... whatever ...; ... other setup for the request ... HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
eeeeaaii Sep 27 '10 at 21:25 2010-09-27 21:25
source share