c# - 每当尝试在 C# 中启动 HttpListener 时出现 HttpListenerException
问题描述
今天我开始更多地研究HttpListener
它是什么,所以如果我对这个或它如何工作的知识不是很广泛,我很抱歉。但是当尝试使用该Start()
方法启动我时,HttpListener
我得到了这个异常:
Can't start the agent to listen transactionSystem.Net.HttpListenerException (32): The process cannot access the file because it is being used by another process.
而且这个例外也与前缀本身有关。
这是我正在使用的代码,这是我第三次不得不重做它,但我仍然遇到同样的异常。
static void ListenTraces()
{
try
{
var httpListener = new HttpListener();
httpListener.Prefixes.Add("https://discord.com/");
try
{
httpListener.Start(); //this line is where the exception happens
}
catch (HttpListenerException hlex)
{
Console.WriteLine("Can't start the agent to listen transaction" + hlex);
return;
}
Console.WriteLine("Now ready to receive traces...");
while (true)
{
var context = httpListener.GetContext();
Console.WriteLine(context.Response);
}
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
}
感谢所有帮助:)
解决方案
可能已经在该端口上监听了其他东西(您是否正在运行任何其他开发服务器?)
尝试通过更改注册表值将代理端口配置为其他端口。
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MsDepSvc\Parameters\ListenUrl
默认情况下,此值应为http://+:80/MSDEPLOYAGENTSERVICE/
. 您可以将 80 更改为例如 81。然后重新启动您的服务。
推荐阅读
- python - 着色 C 参数如何在 hexbin 中工作(Matplotlib,python)
- url - 浏览器中的共享按钮复制以前的 URL 地址
- c++ - 如何使外部定义的全局运算符成为朋友
- wordpress - Wordpress 插件:wp_schedule_single_event 的钩子永远不会被调用
- javascript - 错误“无法读取 null 的属性 'addEventListener'”
- r - 如何在基础 R 中绘制此图表?
- asp.net-core - .NET Core - 增加 Http web api 响应限制
- python - Scrapy将重复的键附加到mongodb列表
- python - Pyspark DataFrame - 转义 &
- git - 我应该在创建新分支之前结帐到 div 吗?