Created
November 9, 2016 13:47
-
-
Save mayrund/d587326feb68218354f5484707e5a301 to your computer and use it in GitHub Desktop.
Capture HTTP request
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
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