Skip to content

Instantly share code, notes, and snippets.

@oscarsan
Created May 20, 2015 07:43
Show Gist options
  • Save oscarsan/a5af58aee0ea96ee77a9 to your computer and use it in GitHub Desktop.
Save oscarsan/a5af58aee0ea96ee77a9 to your computer and use it in GitHub Desktop.
Simple HTTP listener
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var web = new HttpListener();
web.Prefixes.Add("http://10.186.81.191:8080/");
Console.WriteLine("Listening..");
web.Start();
//Console.WriteLine(web.GetContext());
var context = web.GetContext();
var response = context.Response;
const string responseString = "OK";
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
var output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
Console.WriteLine(output);
output.Close();
web.Stop();
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment