Hi @Robin McAninch ,
I suggest you can try to use FormUrlEncodedContent to achieve requesting Web API OAuth token using HttpClient.
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.formurlencodedcontent?view=net-6.0
var client = new HttpClient();
client.BaseAddress = new Uri("***");
var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "client_credentials"),
new KeyValuePair<string, string>("scope", Injected.Instance.Platform.GetId())
});
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", System.Convert.ToBase64String(plainTextBytes));
content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
var result = await client.PostAsync("token",content);
string resultContent = await result.Content.ReadAsStringAsync();
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.