Created
April 10, 2010 13:19
-
-
Save mandykoh/362017 to your computer and use it in GitHub Desktop.
HttpListener example
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.Text; | |
| using System.Threading; | |
| using Naucera.Io.Http; | |
| using Naucera.Net.Http; | |
| public class HttpListenerExample | |
| { | |
| public static void Main(string[] args) | |
| { | |
| using (var listener = new HttpListener(8080, HandleRequest)) { | |
| listener.Start(); | |
| Thread.Sleep(Timeout.Infinite); | |
| } | |
| } | |
| public static HttpResponse HandleRequest(HttpClientConnection conn, HttpRequest request) | |
| { | |
| var content = Encoding.UTF8.GetBytes("Hello, World!"); | |
| var response = new HttpResponse(HttpStatuses.OK, "OK"); | |
| response.Headers.Set("Content-Type", "text/plain"); | |
| response.Body = new ByteArraySource(content); | |
| return response; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment