Skip to content

Instantly share code, notes, and snippets.

@jesslilly jesslilly/Program.cs
Created May 22, 2018

What would you like to do?
HttpClient.cs Authentication Error?
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleTestApp1
class Program
public static void Main(string[] args)
Console.WriteLine("Hello World!");
public static async Task SeedDataInline2()
// Arrange
var client = new HttpClient();
//client.BaseAddress = new Uri(settings.Url);
var login = "abc";
var password = "def";
var requestUri = "https://blah/blah/blah/1";
var credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{login}:{password}"));
//client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
//client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new HttpRequestMessage(HttpMethod.Get, requestUri);
request.Version = Version.Parse("1.1");
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", credentials);
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
//ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Act
var response = await client.SendAsync(request);
// Assert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.