title: C# WebAPI - Get full HTTP request
body: <p>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 <a href="http://web-sniffer.net/" rel="nofollow noreferrer">http://web-sniffer.net/</a>):</p>
  
  <pre><code>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&amp;field2=FIELD2
  Content-type: application/x-www-form-urlencoded
  [...]
  </code></pre>
  
  <p>How can I do this? Both <code>Request</code> and <code>RequestContext</code> don't contain this data and I didn't find any other resource to query for this content.</p>
  
  <p>I tried searching for similar questions on SO, but only found questions for raw content or (if full html) for Java.</p>
  
  <p>In the back of my mind I have a small memory regarding this in combination with the <code>FilterConfig.cs</code>, but sadly nothing specific enough. And with luck someone more knowledgable than me even knows a way to get this information directly.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>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.</p>
  
  <p>According to the link from Jeff's comment in his answer, I have to rebuild the original request from a bunch of parsed fields:</p>
  
  <ul>
  <li><code>HttpContext.Current.Request.HttpMethod</code> + <code>.Url</code> + <code>.ServerVariables["SERVER_PROTOCOL"]</code> for the start line.</li>
  <li><code>HttpContext.Current.Request.ServerVariables["ALL_RAW"]</code> for the headers</li>
  <li><code>Request.Content.ReadAsStreamAsync().Result</code> (don't forget to seek to position 0 before reading) for the content</li>
  </ul>