本文整理汇总了C#中HttpListener.Start方法的典型用法代码示例。如果您正苦于以下问题:C# HttpListener.Start方法的具体用法?C# HttpListener.Start怎么用?C# HttpListener.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpListener
的用法示例。
在下文中一共展示了HttpListener.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FixtureSetup
public void FixtureSetup()
{
_listener = new HttpListener(_uri.OriginalString);
_listener.Start();
_server = new Tracker();
_server.RegisterListener(_listener);
_listener.Start();
}
示例2: StartListener
static void StartListener()
{
listener = new HttpListener();
listener.Prefixes.Add("http://localhost:57789/");
listener.Start();
listener.BeginGetContext(ListenerCallback, listener);
}
示例3: Main
static void Main()
{
Console.Title = "Samples.CustomChecks.3rdPartySystem";
Console.WriteLine("Press enter key to toggle the server to return a error or success");
Console.WriteLine("Press any key to exit");
using (listener = new HttpListener())
{
listener.Prefixes.Add("http://localhost:57789/");
listener.Start();
listener.BeginGetContext(ListenerCallback, listener);
while (true)
{
ConsoleKeyInfo key = Console.ReadKey();
Console.WriteLine();
if (key.Key != ConsoleKey.Enter)
{
return;
}
listener.Close();
if (isReturningOk)
{
Console.WriteLine("\r\nCurrently returning success");
}
else
{
Console.WriteLine("\r\nCurrently returning error");
}
isReturningOk = !isReturningOk;
}
}
}
示例4: Awake
void Awake()
{
listener = new HttpListener();
listener.Prefixes.Add("http://*:7663/");
listener.Start();
listener.BeginGetContext(new AsyncCallback(ListenerCallback), listener);
}
示例5: Listener
public Listener ()
{
EndPoints = new List<IPEndPoint> ();
listener = new HttpListener ();
listener.Prefixes.Add (KeepAliveTest.URL);
listener.Start ();
listener.BeginGetContext (Handle, null);
}
示例6: CreateListener
public HttpListener CreateListener(List<string> addresses)
{
var listener = new HttpListener();
addresses.ForEach(a => listener.Prefixes.Add(a));
listener.Start();
return listener;
}
示例7: NetEventHandler
public NetEventHandler()
{
BaseUrl = Net.GetUrl(Net.GetIp(IPType.All), Net.FindPort(), "").ToString();
ServicePointManager.DefaultConnectionLimit = 100;
_httpListener = new HttpListener();
_httpListener.Prefixes.Add(BaseUrl);
_httpListener.Start();
ThreadPool.QueueUserWorkItem(Listen);
}
示例8: StartListener
public void StartListener (Object args)
{
HttpListener listener = new HttpListener ();
string prefix = string.Format ("http://*:8880/{0}/", args);
listener.Prefixes.Add (prefix);
listener.Start ();
for (; ; ) {
HttpListenerContext ctx = listener.GetContext ();
new Thread (new Worker (ctx).ProcessRequest).Start ();
}
}
示例9: Main
static void Main ()
{
HttpListener listener = new HttpListener ();
listener.IgnoreWriteExceptions = true;
listener.Prefixes.Add ("http://*:8081/");
listener.Start ();
listener.BeginGetContext (RequestHandler, listener);
while (true) {
Thread.Sleep (250);
if (File.Exists ("stop-server.tmp"))
break;
}
listener.Close ();
File.Create ("finish-server.tmp").Close ();
}
示例10: Listen
private static void Listen ()
{
HttpListener listener = new HttpListener ();
listener.Prefixes.Add ("http://127.0.0.1:8080/a/");
listener.Start ();
HttpListenerResponse response = listener.GetContext().Response;
response.ContentType = "text/xml";
byte [] buffer = Encoding.UTF8.GetBytes ("<ok/>");
response.ContentLength64 = buffer.Length;
Stream output = response.OutputStream;
output.Write (buffer, 0, buffer.Length);
output.Close ();
listener.Stop ();
}
示例11: Main
static void Main(string[] args)
{
Console.WriteLine("Started");
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://localhost:8888/decorator/");
listener.Start();
while (true)
{
HttpListenerContext ctx = listener.GetContext();
Console.WriteLine("connected");
ProcessRequest(ctx);
}
}
示例12: Main
static int Main ()
{
HttpListener listener = new HttpListener ();
listener.Prefixes.Add ("http://" + IPAddress.Loopback.ToString () + ":8001/");
listener.Start ();
IAsyncResult result = listener.BeginGetContext (new AsyncCallback (ListenerCallback), listener);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create ("http://" + IPAddress.Loopback.ToString () + ":8001/?a=1&b=2");
request.Accept = "image/png,text/html";
request.Method = "GET";
HttpWebResponse response = (HttpWebResponse) request.GetResponse ();
response.Close ();
result.AsyncWaitHandle.WaitOne ();
return exitCode;
}
示例13: Main
static void Main(string[] args)
{
var port = "1982";
var root = ".";
var prefix = String.Format("http://*:{0}/", port);
Log("listening {0}", prefix);
var listener = new HttpListener();
listener.Prefixes.Add(prefix);
listener.Start();
while (true) {
var context = listener.GetContext();
var request = context.Request;
var response = context.Response;
Log("{0} {1}", request.HttpMethod, request.RawUrl);
if (request.RawUrl == "/api") {
ApiResponse(response, request);
}
else {
var path = root + request.RawUrl;
try {
var content = File.ReadAllBytes(path);
response.ContentType = "text/plain";
response.AppendHeader("Content-Length", content.Length.ToString());
response.OutputStream.Write(content, 0, content.Length);
}
catch (FileNotFoundException e) {
ErrorResponse(response, 404, e);
}
catch (UnauthorizedAccessException e) {
ErrorResponse(response, 403, e);
}
catch (Exception e) {
ErrorResponse(response, 500, e);
}
}
Log(" -> {0}", response.StatusCode);
response.Close();
}
}
示例14: run_server
static void run_server ()
{
HttpListener listener = new HttpListener ();
listener.Prefixes.Add (url);
listener.Start ();
while (server_count < count) {
HttpListenerContext context = listener.GetContext ();
HttpListenerResponse response = context.Response;
string responseString = "my data";
byte [] buffer = Encoding.UTF8.GetBytes (responseString);
response.ContentLength64 = buffer.Length;
Stream output = response.OutputStream;
output.Write (buffer, 0, buffer.Length);
output.Close ();
server_count++;
}
}
示例15: Start
public void Start(int port)
{
if (listener != null && listener.IsListening)
{
return;
}
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "netsh http add urlacl url=http://+:" + port.ToString() + "/ user=" + Environment.UserDomainName + "\\" + Environment.UserName;
process.StartInfo = startInfo;
process.Start();
listener = new HttpListener();
//listener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
try
{
//listener.Prefixes.Add("http://localhost:" + port.ToString() + "/");
listener.Prefixes.Add("http://*:" + port.ToString() + "/");
//listener.Prefixes.Add("http://ip:2006/test/");
//hl.Prefixes.Add("http://*:7867/test/");
listener.Start();
//Console.ReadKey();
}
catch (Exception e)
{
//Console.WriteLine("Error!!!!!!!!!!!!!!");
Console.ReadKey();
throw e;
}
//Console.WriteLine("Started!!!!!!!!!!!!!!!!");
//Console.ReadKey();
running = true;
Thread thread = new Thread(new ThreadStart(listen));
thread.Start();
}