I see in tons of examples on the web using the new HttpClient
object (as part of the new Web API) that there should be HttpContent.ReadAsAsync<T>
method. However, MSDN doesn't mention this method, nor does IntelliSense find it.
Where did it go, and how do I work around it?
It looks like it is an extension method (in System.Net.Http.Formatting):
HttpContentExtensions Class
Update:
PM> install-package Microsoft.AspNet.WebApi.Client
According to the System.Net.Http.Formatting NuGet package page, the System.Net.Http.Formatting
package is now legacy and can instead be found in the Microsoft.AspNet.WebApi.Client
package available on NuGet here.
I have the same problem, so I simply get JSON string and deserialize to my class:
HttpResponseMessage response = await client.GetAsync("Products"); //get data as Json string string data = await response.Content.ReadAsStringAsync(); //use JavaScriptSerializer from System.Web.Script.Serialization JavaScriptSerializer JSserializer = new JavaScriptSerializer(); //deserialize to your class products = JSserializer.Deserialize<List<Product>>(data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With