Created
October 1, 2020 21:13
-
-
Save akeller/fe838fc982e1f938acf6f1c4176d9dfa to your computer and use it in GitHub Desktop.
Digest Auth Example C#
This file contains 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
using System; | |
using System.Threading.Tasks; | |
using System.Net; | |
using System.Net.Http; | |
namespace ConsoleApp1 | |
{ | |
class Program | |
{ | |
private static readonly string user = "<USERNAME>"; | |
private static readonly string password = "<PASSWORD>"; | |
private static readonly string url = "http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications"; | |
private static async Task makeRequest(string url, string user, string password) | |
{ | |
var credCache = new CredentialCache(); | |
credCache.Add(new Uri(url), "Digest", new NetworkCredential(user, password)); | |
var httpClient = new HttpClient(new HttpClientHandler { Credentials = credCache }); | |
var response = await httpClient.GetAsync(url); | |
//var responseString = await response.Content.ReadAsStringAsync(); | |
Console.WriteLine("response: \n" + response); | |
//Console.WriteLine("responseString: \n" + responseString); | |
} | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
makeRequest(url, user, password).Wait(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("There was an exception: {ex.ToString()}"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment