Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diagnostic dump of HttpWebRequest object

Is there any good way (other than tediously querying each property) to build a diagnostic dump string for an HttpWebRequest in C#? For simple objects one can get away with using new JObject(theObject), but that doesn't work for HttpWebRequest (and toString is, of course, as useless on HttpWebRequest as it is on any C# object).

Is there any general way to do this for any subset of C# objects (other than using new JObject as I already mentioned)?

Update: I've found that using JsonConvert.SerializeObject (one suggestion in Hans' link) does a decent job of dumping the HttpWebRequest (though it doesn't get the request stream). And I kind of got the System.Net.Tracing stuff to work (though the documentation, as usual for .NET stuff, sucks royally).

like image 913
Hot Licks Avatar asked Jul 30 '14 21:07

Hot Licks


1 Answers

This turns out to work pretty well:

string httpWebRequestDump(HttpWebRequest hwr)
{
    return JsonConvert.SerializeObject(hwr,Formatting.Indented);
}

The only problem is that it doesn't dump the associated request stream. I have not found a way to extract that from the request.

like image 59
Hot Licks Avatar answered Dec 17 '22 05:12

Hot Licks