How to view headers sent by HttpWebRequest

I clean the site using HttpWebRequest, but the site returns an error. This page works great when I hit it from my browser. I would like to compare them to find out what might cause the error. I know how to intercept a request from my browser to check the headers, but how to view the data sent by HttpWebRequest?

+6
c #
source share
5 answers

To compare what you do in the code and what the browser does, I'm sure an HTTP debugging tool like Fiddler would be the easiest solution.

Fiddler acts as a proxy between the client and server and displays all the information sent over HTTP.

You may need to configure your .NET application to use the proxy provided by Fiddler. This blog post contains detailed information on this.

+8
source

http://www.fiddler2.com/fiddler2/ is a great tool for such things.

+6
source

The Net Firebug panel will display all requests, including headers.

EDIT : You already knew how to do this in the browser as soon as I posted the message. Try the headers property:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.stackoverflow.com"); request.Method = "GET"; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Console.WriteLine(response.Headers); 
+2
source

You can get headers from HTTPWebRequest through the Headers property. From MSDN: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.headers.aspx

0
source

I do not know if there is a general solution. But if you use Firefox, then one of two add-ons will help: Firebug or LiveHTTPHeaders.

-one
source

All Articles