Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using System.Threading;
- using System;
- using System.IO;
- namespace HTTPServer
- {
- public class MyHttpServer {
- public MyHttpServer(){
- start();
- }
- private void start()
- {
- // Create a listener.
- HttpListener listener = new HttpListener();
- listener.Prefixes.Add ("http://localhost:8080/");
- listener.Prefixes.Add ("http://localhost:8080/test/");
- listener.Start ();
- Console.WriteLine ("Listening...");
- while (true) {
- //Anfrage
- HttpListenerContext context = listener.GetContext ();
- HttpListenerRequest request = context.Request;
- HttpListenerResponse response = context.Response;
- //Text in byte umwandeln
- byte[] buffer = formatByte("<html><head><title>Login Service</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head><body bgcolor=\"#FFFFFF\" text=\"#000000\"><h2>Aupheron Login Service</h2>Welcome to the login server from Aupheron <input type=\"submit\" name=\"Abschicken\" value=\"Abschicken\"> </body></html>");
- response.ContentLength64 = buffer.Length;
- System.IO.Stream output = response.OutputStream;
- String text = null;
- StreamReader reader = new StreamReader (request.InputStream, request.ContentEncoding);
- while(true){
- text = reader.ReadLine ();
- if(text != null){
- break;
- }
- }
- Console.WriteLine (text);
- output.Write (buffer, 0, buffer.Length);
- // You must close the output stream.
- output.Close ();
- }
- }
- private byte[] formatByte(String responseString){
- return System.Text.Encoding.UTF8.GetBytes (responseString);
- }
- private String formatString(byte[] buffer){
- return System.Text.Encoding.UTF8.GetString (buffer);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement