C # WebAPI - Get Full HTTP Request

In one of my WebAPI controllers, I would like to see the original raw HTTP request that was sent by the client (like stuff you can see at 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

do not contain this information, and I have not found another resource to request the content.

I tried looking for similar questions on SO but only found questions for raw content or (if full html) for Java.

Deep down, I have a small memory of this combined with FilterConfig.cs

, but unfortunately nothing concrete is enough. And with luck, someone more knowledgeable than me even knows a way to get this information directly.

Edit:

It seems that it is not possible to directly receive the raw HTTP request. After reading the linked answers, it seems that I need to rebuild a query from multiple fields.

According to the link from Jeff's comment in his answer, I have to rebuild the original query from a bunch of parsed fields:

  • HttpContext.Current.Request.HttpMethod

    + .Url

    + .ServerVariables["SERVER_PROTOCOL"]

    for the starting line.
  • HttpContext.Current.Request.ServerVariables["ALL_RAW"]

    for headings
  • Request.Content.ReadAsStreamAsync().Result

    (remember to find position 0 before reading) for content
+3


source to share


1 answer


Install and run Telerik Fiddler. It captures traffic, decodes HTTPS traffic. This is what I use all the time for this purpose.



0


source







All Articles