Problem: HttpClient returns 503 "Service Unavailable" when accessing locally hosted API through console app while it can be accessed successfully using Edge. Am I missing some configurations?
Code:
using System;
using System.Net.Http;
using System.Threading.Tasks;
namespace SampleClient
{
public class Program
{
private static HttpClient Client = new HttpClient();
public static async Task Main(string[] args)
{
Console.WriteLine("Starting connections");
for(int i = 0; i<5; i++)
{
var result = await Client.GetAsync("http://localhost:5100/api/contacts");
//var result = await Client.GetAsync("https://stackoverflow.com/");
Console.WriteLine(result.StatusCode);
}
Console.WriteLine("Connections done");
}
}
}
--- build ---
dotnet build
Microsoft (R) Build Engine version 16.5.0-preview-20064-06+86d9494e4 for .NET Core Copyright (C) Microsoft Corporation. All rights reserved.
...
Build succeeded. 0 Warning(s) 0 Error(s)
sample output: screenshot
Client.DefaultRequestHeaders.Accept.Clear(); Client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json"));
before you callingGetAsync
? – Selim Yildiz