gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:24:59 25 4
gpt4 key购买 nike

我正在尝试在 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/

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