I have a very simple API in C# for test purposes. The API is created in a Windows Forms project
listener = new HttpListener();
listener.Prefixes.Add(url);
listener.Start();
LogUtils.appendInfo("Listening for connections on: " + url);
//Handle requests
Task listenTask = HandleIncomingConnections();
listenTask.GetAwaiter().GetResult();
If I call http://localhost:8080/ I get response from API.
The problem is that if I call the API from another PC using the external IP address http://ExternalIp:8080/
I get this error:
Bad Request - Invalid Hostname HTTP Error 400. The request hostname is invalid
What I have tried:
As @PanagiotisKanavos commented I can not use "localhost" in "listener.Prefixes.Add" for external request.
Solved by:
http://*:8080/
And run Visual Studio as administrator.