Skip to content

Instantly share code, notes, and snippets.

@enkelmedia
Last active September 14, 2021 19:10
Show Gist options
  • Save enkelmedia/237ed805bcc4ef3b589fd1f43726c96c to your computer and use it in GitHub Desktop.
Save enkelmedia/237ed805bcc4ef3b589fd1f43726c96c to your computer and use it in GitHub Desktop.
// Use
var parser = new HttpRequestToTextParser();
var res = parser.Parse(Request);
System.IO.File.AppendAllLines(@"c:\\temp\\log_request.txt",res);
// Implementation
public class HttpRequestToTextParser
{
public List<string> Parse(HttpRequestBase request)
{
var list = new List<string>();
foreach (var headerKey in request.Headers.AllKeys)
{
var values = request.Headers.GetValues(headerKey);
string keyValue = "";
if (values != null)
{
keyValue = string.Join(",", values);
}
list.Add($"{headerKey}:{keyValue}");
}
Stream req = request.InputStream;
req.Seek(0, System.IO.SeekOrigin.Begin);
string body = new StreamReader(req).ReadToEnd();
list.Add("Body:");
list.Add(body);
return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment