Request against localhost relative url "Cannot assign requested address" Request against localhost relative url "Cannot assign requested address" docker docker

Request against localhost relative url "Cannot assign requested address"


I am using the same ASP.NET Core docker version and it seems work as described below:

http://host.docker.internal:<port>

Try again and check if it works for you!


For accessing resource from IIS Express, SelfHost and Docker, you could configure HttpClient.BaseAddress with Http Request like below:

public class HomeController : Controller{    private readonly HttpClient httpClient;    public HomeController(        , IHttpClientFactory httpClientFactory)    {        this.httpClient = httpClientFactory.CreateClient();    }    public async Task<IActionResult> Index()    {        this.httpClient.BaseAddress = new Uri($"{this.Request.Scheme}://{this.Request.Host}");        var response = await httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get,            "data/some.json"));        var result = await response.Content.ReadAsStringAsync();        return View();    }}