Created
July 23, 2021 20:29
-
-
Save SteveDunn/3294f214d120423a28ea9ec8162b3a75 to your computer and use it in GitHub Desktop.
CacheCow client with authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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