0

I am trying to connect to an API in my website and authenticate in it. The API documentation sample is in CURL which I know so little about it.

The CURL command is:

curl -X POST \
   --user ${client_id}:${client_secret} \
http://dashboard.myAPI.ir/oauth/token? grant_type=password&password=${your_login_password}&username=${your_login_user_name}'

and this is my code trying to convert it to C#:

var Username = "myuseranme";
var Password = "mypassword";
var SecretId = "mysecretid";
var ClinetID = "myclientid";

var httpClient = new HttpClient();
var authToken = Encoding.ASCII.GetBytes($"{ClinetID}:{SecretId}");
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic",
                Convert.ToBase64String(authToken));

var response = await httpClient.GetAsync($"http://dashboard.packpay.ir/oauth/token?grant_type=password&pasword={Password}&username={Username}");

var content = await response.Content.ReadAsStringAsync();

After I run the code, the value of content is this:

"{\"error\":\"unauthorized\",\"error_description\":\"Header is missing\"}"

what's wrong?

Shireen
  • 167
  • 1
  • 2
  • 15

0 Answers0