Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.Net.Http.HttpRequestException: Cannot assign requested address - error while communicating between 2 .net core web apps in localhost

I'm new to docker and I have a visual studio solution with 2 dotnet core projects - UI and API. I've added docker support for both projects and they worked normally anytime I debug. Now they have an http client to call the api from the web and it suddenly starts giving the "Cannot assign requested address" error.

The weird thing here is that this error only comes up from just one PC. I have a second PC that still runs the projects smoothly. None of the other team members sees this error.

I've pruned all containers and images but that didn't help. I'm not using docker-compose so the answers I found on related questions can't work for me.

The article here explains how localhost is being interpreted differently in docker but I'm not sure how to make his solution work for me.

The fact that this issue doesn't occur on other PCs is what really baffles me here.

Note: I'm not sure what part of the code I need to share because I don't know what's relevant to this problem.

like image 685
Yusuff Sodiq Avatar asked Sep 05 '25 03:09

Yusuff Sodiq


1 Answers

I had the same problem when creating a client using the localhost url. I replaced http://localhost:5001 with http://host.docker.internal:5001 and it worked.

like image 84
Dorin Baba Avatar answered Sep 07 '25 20:09

Dorin Baba