I use HttpClient
to obtain access token, but I got error Method not allowed
I tried from postman and I was able to get tokens successfully. But even though I use the PostAsync
method of the HttpClient
class, method GET
appears in the response. Isn't that strange?
private async Task<string> GetTokenAsync(string username,string password)
{
string accessToken;
var jsonInput = jsonSerializer.Serialize(new { email = username, password = password });
var requestContent = new StringContent(jsonInput, Encoding.UTF8, "application/json");
var response = await httpClient.PostAsync(@"api/user/token/obtain", requestContent);
response.EnsureSuccessStatusCode();
var content = await response.Content.ReadAsStringAsync();
accessToken = jsonSerializer.Deserialize<IntegraAuth>(content).access;
return accessToken;
}