Skip to content

Instantly share code, notes, and snippets.

@powerumc
Created May 5, 2020 12:51
Show Gist options
  • Save powerumc/fbf71b4dbd4d3b9c2a428864057aa16e to your computer and use it in GitHub Desktop.
Save powerumc/fbf71b4dbd4d3b9c2a428864057aa16e to your computer and use it in GitHub Desktop.
using System;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace MonoConsoleApp1
{
internal class Program
{
public static async Task Main(string[] args)
{
using (var listener = new HttpListener())
{
listener.Prefixes.Add("http://localhost:8080/");
Console.WriteLine("Ready...");
listener.Start();
while (listener.IsListening)
{
var context = await listener.GetContextAsync();
var buffer = Encoding.UTF8.GetBytes("hello world");
context.Response.ContentLength64 = buffer.Length;
await context.Response.OutputStream.WriteAsync(buffer, 0, buffer.Length);
}
listener.Stop();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment