Skip to content

Instantly share code, notes, and snippets.

@mayrund
Created November 9, 2016 13:47
Show Gist options
  • Save mayrund/d587326feb68218354f5484707e5a301 to your computer and use it in GitHub Desktop.
Save mayrund/d587326feb68218354f5484707e5a301 to your computer and use it in GitHub Desktop.
Capture HTTP request
private string GetRequest()
{
var headers = String.Empty;
StringBuilder sb = new StringBuilder();
sb.AppendLine("URL: " + Context.Request.Url);
sb.AppendLine("IP address:" + Context.Request.UserHostAddress);
sb.AppendLine("HttpMethod " + Request.HttpMethod);
sb.AppendLine("Header:");
foreach (var key in Request.Headers.AllKeys)
sb.AppendLine(key + "=" + Request.Headers[key]);
sb.AppendLine("Body:");
sb.AppendLine(GetDocumentContents(Request));
return sb;
}
private string GetDocumentContents(System.Web.HttpRequest Request)
{
var httpRequestBase = new HttpRequestWrapper(Request);
string documentContents;
using (Stream receiveStream = Request.InputStream)
{
using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8))
{
documentContents = readStream.ReadToEnd();
}
}
return documentContents;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment