替代/等效的ReadAsAsync <t>

时间:2016-05-16 22:46:41

标签: c# asp.net httpclient

我从.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>();

的替代品

0 个答案:

没有答案