我收到错误 AuthTokenRS值=等待response.Content.ReadAsAsync(); 错误消息是:
'HttpContent'不包含'ReadAsAsync'的定义,也没有扩展方法'ReadAsAsync',也没有找到接受'HttpContent'类型的第一个参数的扩展方法'ReadAsAsync'(你是否缺少using指令或者汇编参考?)。
这是我的代码段:
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);
}
}
}