我从.net框架4升级到4.6。
public static async Task<bool> SignIn(string userName, string password)
{
var user = new { UserName = userName, Password = password };
// HttpResponseMessage response = await CallAPI(client => client.PostAsJsonAsync("api/account/SignIn", user));
HttpResponseMessage response = await CallAPI(client => client.PostAsync("api/AgentCollection", new StringContent(new JavaScriptSerializer().Serialize(user), Encoding.UTF8, "application/json")));
bool result = false;
if (response.IsSuccessStatusCode)
{
result = await response.Content.read.ReadAsAsync<bool>();
}
return result;
}
在上面的代码中
我在PostAsJsonAsync
收到错误。基于此Article
我将client.PostAsJsonAsync("api/account/SignIn", user);
更改为client.PostAsync("api/AgentCollection", new StringContent(new JavaScriptSerializer().Serialize(user), Encoding.UTF8, "application/json"))
现在我收到了ReadAsAsync()的错误信息。
什么应该是result = await response.Content.read.ReadAsAsync<bool>();