Skip to content

Instantly share code, notes, and snippets.

@SteveDunn
Created July 23, 2021 20:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SteveDunn/3294f214d120423a28ea9ec8162b3a75 to your computer and use it in GitHub Desktop.
Save SteveDunn/3294f214d120423a28ea9ec8162b3a75 to your computer and use it in GitHub Desktop.
CacheCow client with authentication
public class RunWithCacheCow
{
private readonly HttpClient _client;
public RunWithCacheCow()
{
var httpClientHandler = new HttpClientHandler()
{
Credentials = new NetworkCredential("test", "test"),
};
_client = ClientExtensions.CreateClient(httpClientHandler);
_client.DefaultRequestVersion = HttpVersion.Version20;
}
public async Task Run()
{
try
{
var response = await _client.GetStringAsync("https://localhost:55511/WeatherForecast/london");
Console.WriteLine(response);
}
catch (HttpRequestException e)
{
Console.WriteLine("\nException Caught!");
Console.WriteLine("Message :{0} ", e.Message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment