How to directly monitor HTTP requests from the C # server console?

Does anyone know how to get a C # server application running in the console to display HTTP requests from the client as shown in this image?

http://imgur.com/filhZJZ

Thanks in advance!

+3


source to share


2 answers


If all you want to do is deploy an HTTP server and write requests to the console, this should be fairly easy to accomplish with OWIN and Katana . Just install the following NuGet packages:

  • Microsoft.Owin.Hosting
  • Microsoft.Owin.Host.HttpListener

And use something along the following lines:

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, customize the output to your liking, having access to full query and spam objects.

This will give you something like this:

HTTP requests

+2


source


You can do this using System.Diagnostics Tracing

in Web API

. On the asp.net website you can read a detailed article .

Another possibility is to enable IIS logging and then read the log files. I'm not really sure how it's done, this is what I'm doing on apache2 / linux wherever you can tail -f log

. I've read a thing or two about powershell equivalents, but not for consoleapps, so I think I'll stick with Tracing.



Edit: After looking around I found this similar question with related answers: How do I view the raw HTTP request sent by the HttpWebRequest class?

0


source







All Articles