❔ Make my api accessible
If we create a webapi using the dotnet new webapi template, the api is accessible using two different urls: https://localhost:port and http://localhost:port.
How to make it accessible through my private ip address rather than localhost? I wanna call
https://myprivateip:port.
13 Replies
just for testing purposes or more long-term?
and do you want access only within your local network, or outside internet access?
the api only has a single endpoint that returns "success" or "fail", its not a productive api. The purpose of the project is to have a communication over the nethwork with an esp32-eye board. I wanna send post request from the esp32-eye board when a button is pressed to my api
therefore my api has to be accessible for the board
That doesnt answer my questions.
either is fine
i suppose private network is easier so lets stick to that
if you open up "launchSettings.json"
you should see the applicationUrl listed there
change from "localhost" to "0.0.0.0" and it will listen on all interfaces, meaning it will be as accessible as it can
oh so it will react to anyPrivateIP:Port?
that should be enough for local network access. For outside internet access, you will need port forwarding (if using a router)
yeah it will bind to all available interfaces
localhost
is a special network interface called "loopback"
ie, localhost is available even if your computer doesnt even have a network card at allgonna try that, thank you very much
@Pobiega I have launch.json and I have appsettings.json but I do not have launchsettings.json
do i have to create that file myself?
what .NET version?
but no, you shouldn't have to.
it really should be there :p
oh under properties, I do have it
thx
if 0.0.0.0 doesnt work, try
https://+:port
or *
(instead of +
), the documentation lists all 3 in various places
*
seems to be recommendedWas this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.