In one of my WebAPI Controllers, I'd like to see the original raw HTTP request which was sent by the client (like the stuff you can see on http://web-sniffer.net/):
POST / HTTP/1.1
Host: www.some.host.tld
Connection: keep-alive
Accept-Encoding: gzip[CRLF]
Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7
field1=FIELD1&field2=FIELD2
Content-type: application/x-www-form-urlencoded
[...]
How can I do this? Both Request
and RequestContext
don't contain this data and I didn't find any other resource to query for this content.
I tried searching for similar questions on SO, but only found questions for raw content or (if full html) for Java.
In the back of my mind I have a small memory regarding this in combination with the FilterConfig.cs
, but sadly nothing specific enough. And with luck someone more knowledgable than me even knows a way to get this information directly.
Edit:
It seems, that it is impossible to capture the raw HTTP request directly. After reading the linked answers, it seems that I have to rebuild the request from several fields.
According to the link from Jeff's comment in his answer, I have to rebuild the original request from a bunch of parsed fields:
HttpContext.Current.Request.HttpMethod
+.Url
+.ServerVariables["SERVER_PROTOCOL"]
for the start line.HttpContext.Current.Request.ServerVariables["ALL_RAW"]
for the headersRequest.Content.ReadAsStreamAsync().Result
(don't forget to seek to position 0 before reading) for the content