Alternative / Equivalent ReadAsAsync <T>

I upgraded from .net framework 4 to 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;
        }

In the code snippet above, I received an error message PostAsJsonAsync. Based on this article I changed client.PostAsJsonAsync("api/account/SignIn", user);toclient.PostAsync("api/AgentCollection", new StringContent(new JavaScriptSerializer().Serialize(user), Encoding.UTF8, "application/json"))

Now I get the following error for ReadAsAsync (). what should be a replacementresult = await response.Content.read.ReadAsAsync<bool>();

+4
source share

All Articles