gpt4 book ai didi

c# - .NET Core 中 HttpListener 的模拟是什么

转载 作者:可可西里 更新时间:2023-11-01 08:55:05 25 4
gpt4 key购买 nike

我正在将应用程序从 .NET 4 移植到 .NET Core,但找不到 HttpListener 类的模拟

Error   CS0246  The type or namespace name 'HttpListener' could not be found (are you missing a using directive or an assembly reference?)  

更新1

        private readonly HttpListener _httpListener;

if (!HttpListener.IsSupported)
{
throw new NotSupportedException(
"The Http Server cannot run on this operating system.");
}

_httpListener = new HttpListener();
_httpListener.Prefixes.Add(prefix);
_sessionSettings = settings;

最佳答案

如评论中所述,WebListener(在 Microsoft.Net.Http.Server NuGet 包中)是最接近的替代品,但具有不同的 API。或者,还有 Kestrel HTTP 服务器,它最好从 ASP.NET Core 堆栈中使用,但可以单独使用(但很难设置)。

如果您正在移植,我建议等到 .NET Core 2.0,它有一个 API compatible HttpListener跨平台工作,不需要您完全更改代码。

关于c# - .NET Core 中 HttpListener 的模拟是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43951619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com