Created
May 20, 2015 07:43
-
-
Save oscarsan/a5af58aee0ea96ee77a9 to your computer and use it in GitHub Desktop.
Simple HTTP listener
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.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