This line of code:
await response.Content.ReadAsAsync<AuthenticatedUser>();
returns "null", when it's supposed to return an <AuthenticatedUser> with a Username and Password.
I saw a similar problem here:
Response.content.readasasync returns null[
^], however, the answer provided did not help me.
What I have tried:
Here's what I've got so far:
public async Task<AuthenticatedUser> Authenticate(string username, string password)
{
var data = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", username),
new KeyValuePair<string, string>("passsword", password)
});
using (HttpResponseMessage response = await apiClient.PostAsync("/token", data))
{
if (response.IsSuccessStatusCode)
{
var result= await response.Content.ReadAsAsync<AuthenticatedUser>();
return result;
}
else
{
throw new Exception(response.ReasonPhrase);
}
}
}
I tried replacing
await response.Content.ReadAsAsync<AuthenticatedUser>();
with
await response.Content.ReadAsAsync<object>();
, which in return required changing the void and interface to
Task<object>
, too. To no avail.
I also tried replacing
var
with
AuthenticatedUser
and it didn't work either. Any ideas how to bypass this problem?