I have been using HttpClient
for making WebApi calls using C#. Seems neat & fast way compared to WebClient
. However I am stuck up while making Https
calls.
How can I make below code to make Https
calls?
HttpClient httpClient = new HttpClient();
httpClient.BaseAddress = new Uri("https://foobar.com/");
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(
new MediaTypeWithQualityHeaderValue("application/xml"));
var task = httpClient.PostAsXmlAsync<DeviceRequest>(
"api/SaveData", request);
EDIT 1: The code above works fine for making http calls. But when I change the scheme to https it does not work. Here is the error obtained:
The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
EDIT 2: Changing the scheme to https is: step one.
How do I supply certificate & public / private key along with C# request.
new Uri("https://foobar.com/");