does anyone know how to get a C# server application running in the console to display HTTP requests from a client as shown in this image?
https://i.stack.imgur.com/vC0k1.jpg
Thanks in advance!
does anyone know how to get a C# server application running in the console to display HTTP requests from a client as shown in this image?
https://i.stack.imgur.com/vC0k1.jpg
Thanks in advance!
If all you want to do is spin up an HTTP server and write out requests to the console, it should be pretty easy to accomplish using OWIN and Katana. Just install the following NuGet packages:
And use something along the lines of the following:
public static class Program
{
private const string Url = "http://localhost:8080/";
public static void Main()
{
using (WebApp.Start(Url, ConfigureApplication))
{
Console.WriteLine("Listening at {0}", Url);
Console.ReadLine();
}
}
private static void ConfigureApplication(IAppBuilder app)
{
app.Use((ctx, next) =>
{
Console.WriteLine(
"Request \"{0}\" from: {1}:{2}",
ctx.Request.Path,
ctx.Request.RemoteIpAddress,
ctx.Request.RemotePort);
return next();
});
}
}
You can of course tweak the output to your liking, having access to the full request and respose objects.
It will give you something like this:
You can do this using System.Diagnostics Tracing
in Web API
. On the asp.net website, you'll be able to read a detailed article.
Another possibility is turning on the IIS logging and then read the logfiles. I'm not quite sure how this is done, it's just what I do on apache2/linux, where you can tail -f log
. I read something about powershell equivalents, but not for consoleapps, so I think I would stick with the Tracing.
Edit: After some looking around on SO I found this similar question with relevant answers: How do I see the raw HTTP request that the HttpWebRequest class sends?