using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
namespace LHJHttpServer
{
public class MainHttpListener
{
public string listenerUrl = "http://192.168.0.102:7890/";
public HttpListener httpListener;
public MainHttpListener()
{
this.StartListener();
}
private void StartListener()
{
try
{
httpListener = new HttpListener();
httpListener.AuthenticationSchemes = AuthenticationSchemes.Anonymous;
httpListener.Prefixes.Add(listenerUrl);
httpListener.Start();
Console.WriteLine("启用数据监听!");
httpListener.BeginGetContext(ListenerHandle, httpListener); //开始监听
}
catch(Exception e)
{
Console.WriteLine($"服务器启动失败!{e.Message}");
C# 监听Http请求并返回数据
最新推荐文章于 2024-04-23 08:29:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)