Last active
September 14, 2021 19:10
-
-
Save enkelmedia/237ed805bcc4ef3b589fd1f43726c96c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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