.NET HttpListener : when registering both HTTP & HTTPS I get "conflicts with an existing registration on the machine"

标签 .net httplistener

我正在尝试在 C# 项目中使用 .NET HttpListener。当我注册我的前缀“http://*:8080/”时,它似乎不适用于 HTTPS 网址(即不接收它们)。当我尝试使用以下代码注册前缀的 HTTP 和 HTTPS 版本时,出现错误:

“无法监听前缀‘https://:8080/’,因为它与机器上的现有注册冲突。”*

如何让我的前缀同时适用于 HTTP 和 HTTPS?

    private HttpListener _listener;

    // Create prefixes
    var prefixes = new List<string>();
    prefixes.Add("http://*:8080/");
    prefixes.Add("https://*:8080/");


    // Create HttpListener
    _listener = new HttpListener();
    foreach (string prefix in prefixes)
    {
        _listener.Prefixes.Add(prefix);
    }

    _listener.Start();   // <== ERROR HERE

编辑 1 - 附加说明:
  • 该程序用作发出 HTTP(S) 调用的 PC 应用程序的本地代理。
  • 因此,使用基于更改浏览器代理设置以指向此本地本地代理服务器(例如 localhost:8080)
  • 因此,这意味着(我假设)HttpListener 必须在同一本地端口(例如 8080)上监听 HTTP 和 HTTPS 流量。
  • 目标:尝试为我的程序找到一种方法来监听同一端口上的 HTTP 和 HTTPS .

  • 谢谢

    最佳答案

    OBJECTIVE: Try to find a way for my program to listen to both HTTP and HTTPS on the same port.



    不能使用 HTTPListener 执行此操作。您需要使用 TCPListener并根据是 HTTP 还是 HTTPS 有条件地处理每个响应。

    我很确定,如果您将一个 HTTPListener 用于 HTTP 8080,一个用于 HTTPS 8443,您应该能够让您的浏览器将 yourproxy:8080 用于 HTTP,将 yourproxy:8443 用于 HTTPS。 Firefox 绝对让您做到这一点。

    关于.NET HttpListener : when registering both HTTP & HTTPS I get "conflicts with an existing registration on the machine",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2619251/

    相关文章:

    java - 如何从 URL 重定向到 Wildfly 上的某个端口

    .net - HttpListener 响应刷新到 'large' 缓冲区很快

    c# - 测试完成后关闭连接

    .net - 将GCP凭据添加到.net核心应用程序中的Docker

    c# - Windows 硬重启

    c# - 在回调中重用回调时如何防止 StackOverflowException?

    c# - 如何检查我的解决方案是否包含非托管代码?

    c# - 如何在不阻塞当前线程的情况下发布 HTTP 请求并等待回调?

    .net - QTP DotNetFactory 与 COM 可见的 .NET 程序集