HttpRequestException: No connection could be made because the target machine actively refused it (localhost:5001)
Nothing is listening on the host/port the client called — the API isn’t running, uses another port, or the container/network address is wrong.
Seen on:
.NET
Meaning
“Actively refused” means the TCP connection got a reset. Calling localhost from inside Docker, using http vs https ports incorrectly, or the service crashed at startup are typical.
Common causes
- Target service not running or crashed
- Wrong port (http vs https, launchSettings change)
- localhost used inside a container
- Firewall rejecting
⚡ Quick fix
- Check the service is running and the port it listens on
- Use the Docker service name / host.docker.internal
- Match the base address to the API’s URLs
Detailed fix by platform
Shell
- csharp
netstat -ano | findstr :5001 curl -v http://localhost:5000/health
How to diagnose
- Listening — Port open?
- Address — Base URL correct for the environment?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- CannotPullContainerError ECS task stopped: CannotPullContainerError: pull image manifest has been retried ... / ref pull has been retried
- default backend - 404 Ingress returns "404 Not Found" / "default backend - 404" (ingress-nginx)
- DNS in pod DNS not working inside a Kubernetes pod (could not resolve host / nslookup: can't resolve)
Most viewed in .NET
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026