如果是远程ip,C#httplistener错误

如果是远程ip,C#httplistener错误,c#,webclient,httplistener,C#,Webclient,Httplistener,我创建了一个httplistener,它只能使用localhost作为前缀。如果我将其更改为远程服务器ip,则会显示错误 代码如下: HttpListener listener = new HttpListener(); listener.Prefixes.Add("http://*:8080/"); // I need localhost replaced with remote ip listener.Start(); while (tru

我创建了一个httplistener,它只能使用localhost作为前缀。如果我将其更改为远程服务器ip,则会显示错误

代码如下:

 HttpListener listener = new HttpListener();
        listener.Prefixes.Add("http://*:8080/");  // I need localhost replaced with remote ip
        listener.Start();
        while (true)
        {
            // Wait for a client request:
            HttpListenerContext context = listener.GetContext();

            // Respond to the request:
            string msg = "You asked for: " + context.Request.RawUrl;
            context.Response.ContentLength64 = Encoding.UTF8.GetByteCount(msg);
            context.Response.StatusCode = (int)HttpStatusCode.OK;

            using (Stream s = context.Response.OutputStream)
            using (StreamWriter writer = new StreamWriter(s))
                writer.Write(msg);
        }
        listener.Stop();
这是web客户端:

   using (WebClient wc = new WebClient())        // Make a client request.
                    wc.DownloadString
                      ("http://"my public ip"(on  my router):8080/lg.txt"); //port forwarding is set
                MessageBox.Show("received");
只有当我将“我的公共ip”更改为本地ip时,它才起作用
有什么想法吗?

你的Windows防火墙打开了吗?尝试禁用它,看看是否有帮助。您可能需要实际禁用Windows防火墙服务(在本地服务列表中)。

首先,检查防火墙。不过,可能更可能的是http.sys,它由HttpListener使用——您必须通过“netsh”使前缀对帐户可用。您可以通过作为提升的管理员帐户短暂运行来检查这一点-如果有效,可能是http.sys权限问题。

“远程服务器IP”-远程到谁?它必须是本地服务器…@Marc我是说我的公共IP地址不是我所知道的。。。我认为这将是一个相当大的安全漏洞(如果一个程序可以添加防火墙规则——一个恶意程序可以向世界开放你的计算机)。