【发布时间】:2014-01-28 13:16:56
【问题描述】:
使用以下代码:
HttpListener listener = new HttpListener();
//listener.Prefixes.Add("http://*:80/");
listener.Prefixes.Add("http://*:8080/");
listener.Prefixes.Add("http://*:8081/");
listener.Prefixes.Add("http://*:8082/");
listener.Start();
HttpListenerContext context = listener.GetContext();
HttpListenerRequest request = context.Request;
尽管在 IE 和 Firefox 中加载了 http(不是 https)页面,但程序仍挂在 GetContext();。
当我取消注释第一行时,我得到了错误:
未能侦听前缀“http://*:80/”,因为它与 机器上的现有注册。
那么如何监听浏览器的请求呢?
【问题讨论】:
-
你在运行另一个网络服务器……还是 Skype?
-
@minitech 什么都没有。简单的 Windows 7,没有网络内容。 (当然,Visual Studio 正在运行。)
-
你需要一个代理,fiddler2.com,fiddler2.com/fiddlercore
-
您在浏览器中输入的网址是什么? HttpListener 不会拦截对其他站点的请求,它只是处理指向它的请求。
-
你在你的机器上的 80 端口上运行任何东西吗?你能telnet到80端口吗?
标签: c# .net http httplistener