4

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 headers
  • Request.Content.ReadAsStreamAsync().Result (don't forget to seek to position 0 before reading) for the content
2
  • This 1 line will solve your issue var data = Request.Headers; Commented Apr 12, 2017 at 12:37
  • @DanEsparza The answer you linked to (14967457) doesn't help. The answer linked by Jeff Davies in his comment to his answer (1038466) put me on the right track. Please remove or edit your duplicate marker, so that it won't lead others astray to a wrong answer (to my question) when reading this. Commented Apr 13, 2017 at 7:39

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

I think the OP wants a code solution.
in that case, I guess this question is a duplicate of this: stackoverflow.com/questions/1038466/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.