Created
May 5, 2020 12:51
-
-
Save powerumc/fbf71b4dbd4d3b9c2a428864057aa16e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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