rendered paste bodyusing System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;
namespace httplistnerdemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add(textBox1.Text);
listener.Start();
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
WebHeaderCollection hc = (WebHeaderCollection)request.Headers;
listBox1.Items.Add(request.UserAgent);
for (int i = 0; i < hc.Count; i++)
{
listBox1.Items.Add(hc.GetKey(i) + "=" + hc.Get(i));
}
HttpListenerResponse response = context.Response;
WebHeaderCollection hrc = context.Response.Headers;
string responsestring = "<html><title>http listnet demo</title><body>HELLO WORLD!</body></html>";
byte[] buffer= Encoding.UTF8.GetBytes(responsestring);
response.ContentLength64 = buffer.Length;
Stream output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
output.Close();
}
}
}