title: getting post data from request is coming back null
body: <p>I am using Asp.net MVC and I'm trying to debug my method by writing the post data to a log file.</p>
  
  <p>I took this post <a href="https://stackoverflow.com/questions/1708110/c-sharp-net-equivilent-of-http-raw-post-data">C# .net equivilent of HTTP_RAW_POST_DATA?</a> and tried to run with it. </p>
  
  <p>Here is my <code>ActionResult</code>:</p>
  
  <pre><code>   public ActionResult Receipt(string id)
      {
        try
        {
          using (var sw = new StreamWriter(@"C:\LOGS\RECEIPTLOG.TXT", true))
          {
            sw.WriteLine("-------------------------------------------");
            sw.WriteLine("Start Receipt: " + DateTime.Now);
            sw.WriteLine("Browser: " + Request.Browser.Id);
            sw.WriteLine("Browser Version: {0}.{1}", Request.Browser.MajorVersion, Request.Browser.MinorVersion);
            sw.WriteLine("Request.UserHostAddress: " + Request.UserHostAddress);
            if (Request.UrlReferrer != null)
            {
              sw.WriteLine("Request.UrlReferrer: " + Request.UrlReferrer);
            }
  
            foreach (var headerKey in Request.Headers.Keys)
            {
              var headerValues = Response.Headers.GetValues(headerKey.ToString());
              if (headerValues != null)
              {
                sw.WriteLine("Response Header: {0}, Value: {1}", headerKey, String.Join(";", headerValues));
              }
            }
          }
        }
        catch (Exception ex)
        {
          Console.WriteLine("error:" + ex.Message);
        }
  
        var control = Logging.StartLog();
        control.Source = SourceEnum.WebPortal;
  
        try
        {
          Logging.WriteLog("Start Receipt");
  
          var count = 0;
          var postVals = new Dictionary&lt;string, string&gt;();
          foreach (var key in Request.Form.AllKeys)
          {
            Logging.WriteLog("count: " + count);
            Logging.WriteLog(string.Format("key:   {0}    Value:   {1}", key, Request.Form[key]));
            postVals.Add(key, Request.Form[key]);
            Logging.WriteLog("finished count: " + count);
            count++;
          }
          Logging.WriteLog("finished processing ALLKeys");
          var paymentReq = createPaymentRequest(postVals);
          Logging.WriteLog("finished processing 'var paymentReq = createPaymentRequest(postVals)' ");
  
          Logging.WriteLog("_client.RecordPaymentWithRequest start");
          var receipt = _client.RecordPaymentWithRequest(paymentReq);
          Logging.WriteLog("Running _client.RecordPaymentWithRequest complete");
          var retval = PartialView(receipt.Duplicate ? "Duplicate Receipt" : "Receipt", receipt);
          Logging.WriteLog(string.Format("retval: {0}", retval));
          return retval;
        }
        catch (Exception ex)
        {
          Logging.WriteException(ex);
          throw;
        }
        finally
        {
          Logging.WriteLog(control, "End RegisterNewAccountEmail");
  
          try
          {
            using (var sw = new StreamWriter(@"C:\LOGS\RECEIPTLOG.TXT", true))
            {
              sw.WriteLine("Stop Receipt: " + DateTime.Now);
            }
          }
          catch (Exception ex)
          {
            Console.WriteLine("error:" + ex.Message);
          }
  
        }
      }
  </code></pre>
  
  <p>This is what ends up in my log:</p>
  
  <pre><code>-------------------------------------------
  Start Receipt: 1/14/2014 7:17:07 AM
  Browser: internetexplorer
  Browser Version: 11.0
  Request.UserHostAddress: xxx.xxx.xxx.xxx
  Request.UrlReferrer: website url here
  Stop Receipt: 1/14/2014 7:17:07 AM
  </code></pre>
  
  <p>As you can see there is no header information being written.</p>
  
  <p>Am I going about this wrong to dump the post data into a log file? If not, any ideas why my header information isn't writing to the log?</p>
  
  <p>** UPDATE **</p>
  
  <p>I added this to my logging within the first try/catch:</p>
  
  <pre><code>sw.WriteLine("Request.Headers.Keys.Count: " + Request.Headers.Keys.Count);
  </code></pre>
  
  <p>and this is the results:</p>
  
  <pre><code>Request.Headers.Keys.Count: 11
  </code></pre>