I'm trying to connect to URL using C#.
Basically I'm trying to do the same thing as CURL :
curl -i -k --user ABC..:XYZ.. --data "grant_type=client_credentials" https://www.example.com/oauth/token
Here is my C# code :
// Get the URL
string URL = "https://www.example.com/oauth/token";
//Create the http client
HttpClient client = new HttpClient();
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Post, URL);
requestMessage.Headers.Add("contentType", "application/x-www-form-urlencoded");
requestMessage.Headers.Add("data", "grant_type=client_credentials");
requestMessage.Headers.Add("user", "ABC..:XYZ..");
//Connect to the URL
HttpResponseMessage response = client.SendAsync(requestMessage).Result;
// Get the response
string Output = response.Content.ReadAsStringAsync().Result;
Curl code works great. And I get a 200 status response. However in C#, I'm having the response : 401, Unauthorized. It seems like client id and key are not provided in the correct format.
Does anyone know what is missing in my C# code please ?
Thanks, cheers