I am getting an error on AuthTokenRS value = await response.Content.ReadAsAsync(); The error message is:
'HttpContent' does not contain a definition for 'ReadAsAsync' and no extension method 'ReadAsAsync' and no extension method 'ReadAsAsync' accepting a first argument of type 'HttpContent' could be found(are you missing a using directive or an assembly reference?).
Here is my code snippet:
public async Task<HttpResponse<AuthTokenRS>> AuthorizeAsync(string credentials)
{
using (HttpClient client = new HttpClient())
{
client.BaseAddress = new Uri(this.config.Environment);
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", credentials);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
var args = new Dictionary<string, string>();
args.Add("grant_type", "client_credentials");
var content = new FormUrlEncodedContent(args);
Logger.DebugFormat("POST {0}\n{1}", AuthorizationEndpoint, await content.ReadAsStringAsync());
var response = await client.PostAsync(AuthorizationEndpoint, content);
string requestUri = response.RequestMessage.RequestUri.ToString();
if (response.IsSuccessStatusCode)
{
//AuthTokenRS value = await response.Content.ReadAsAsync<AuthTokenRS>();
AuthTokenRS value = await response.Content.ReadAsAsync<AuthTokenRS>();
return HttpResponse<AuthTokenRS>.Success(response.StatusCode, value, requestUri);
}
else
{
return HttpResponse<AuthTokenRS>.Fail(response.StatusCode, await response.Content.ReadAsStringAsync(), requestUri);
}
}
}