Windows 10 WSL cURL can't access localhost with error (Failed to connect to localhost port 80: Connection refused)
I suspect you're actually running WSL2, which handles networking almost entirely differently from how WSL handled it. See this issue on git for a very long breakdown of what's happening and why.
The short answer: it's not going to be easy to get localhost
running the way you'd like on WSL2, and I've personally downgraded to WSL (the first version) for the moment until they finally offer a method to do that without both having to map all of your requests to an arbitrary assigned-on-startup IP and opening your Windows firewall rules up to allow public inbound connections on your service port.
If you do want to downgrade and magically have localhost
interactions back, just open a Powershell console as admin and enter the following (assuming running an Ubuntu release):
wsl --set-version Ubuntu 1
You'll lose any WSL2 features but regain your sanity. Note that there may be one or two migration tasks to perform on the Ubuntu instance itself.
A quick workaround is to set an alias to the cmd version of curl and use that from wsl2.
In you ~/.bashrc, set following:
alias curl="cmd /C curl"
After you restart or source .bashrc, you can use curl as usual.
If you need to use it in a bash script, where your aliases is not set, you can use cmd /C curl
in the scripts. It is ugly but it works.