It can be extremely beneficial to visually see the raw list of Http Headers that will actually be sent or received in WebAPI's HttpResponseMessage / HttpRequestMessage types. I mean just a plain old string, with each header on a new line, exactly what is generated or received.
But unfortunately, it does not look like either of these types allows you to just see what actually gets generated. Instead, there are properties scattered everywhere. Some in the raw HttpResponseMessage / HttpRequestMessage types themselves, some in the response/request.Content.Headers (the two do not repeat, the latter is for ones not already covered as properties, typically for custom headers), ... and maybe Cookies somewhere gets a stash of its own headers. And visually getting to see those lists of Header collections is a pain as well, i.e. you end up with a bunch of iterating code for each such collection ... more mess.
But in the actual response / request sent / received, there is no such division, and it is simple to see all Http headers. So am I missing it somewhere? Is there actually a simple and intuitive property somewhere in these that simply returns the raw headers string? Certainly the response already received the headers and just parsed them ... is that raw string hidden somewhere?
(BTW, I know about Fiddler... and that is entirely unsatisfactory. If I am having to deal with low-level messing of Http headers, then it makes good sense to be able to view them with the programmatic type I am using to generate and receive them with. But worse off, I still can't get localhost to work with Fiddler (on Win8), which invalidates its use for many debugging scenarios where all I want to do is see the stinking headers that will be generated.)
I did not find a way to get the raw value of request headers, but this code seems to return all the header values (not in original order):
request.Headers.ToString() + request.Content.Headers.ToString()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With