I am designing a http server using .NET. I basically use HttpListener to get http request from client. At the beginning, I have to specify the URL, and add that URL to HttpListener. Then, I have to let the HttpListener to start to listen. The problem occurs when it starts to listen. It generate an exception when it starts to listen.
The code is the following:
string url = "http://*:80/"; //where * is the IP address of my PC.
listener = new HttpListener();
listener.Prefixes.Add(url);
listener.Start(); //this is where exception occurs, it couldn't start!!!
My guess is that I have to register that URL using netsh. Is it correct?
I can think of two simple reasons this might be happening:
The exception should indicate which of these is the case. It's always important to pay attention to exception messages - a lot of errors can be fixed just by reading exceptions carefully.
It's probably simplest to start off listening on a different port.
EDIT: In running a few experiments I've found:
See more on this question at Stackoverflow