Extract contents from HttpResponseMessage

10,954

Solution 1

You can use the .ReadAsAsync<List<T>> method of the Content property.

Please also read my sample from this answer.

Update: These extension methods are located in the System.Net.Http.Formatting namespace inside the NuGet Package Microsoft.AspNet.WebApi.Client.

Solution 2

This is no longer possible. Check this out: http://aspnetwebstack.codeplex.com/discussions/350492

Share:
10,954
Nicolás Straub
Author by

Nicolás Straub

I am a computer nerd. I learned programming when I was 6, started working when I was 16, and haven't stopped since. My specialties are the user experience, domain architecture, tooling, and refactoring. I have served as architect and manager for multiple projects, leading teams of up to 5 people. I firmly believe in learning the underlying theory when it comes to software development, so instead of reading "teach yourself PHP in 2 weeks" or "Python in 24 hours" I prefer "Design Patterns", "Refactoring", "Analysis Patterns", "Domain-Driven Design" and other books which tell stories of the underlying patterns, paradigms and practices that compose software development. This gives me a perspective which allows me to pick up any language and start working with it in days. With that said, being a C# and JavaScript expert, I have read the most technical books on those subjects and have in-depth knowledge of how JS, C# and the .Net CLR work. I value TDD and SOLID practices, but take a pragmatic approach to them. So, you wont find me writing fifty-four unit tests for 3 lines of code or a hundred 3-line files, for the sake of not violating the Single Responsibility Principle. When Im not working Im either learning more about software development or playing with my 8-year old. Hes starting to take an interest in programming so maybe these two worlds will collide. for now, the joy of being a loving father to him is what keeps me going.

Updated on June 05, 2022

Comments

  • Nicolás Straub
    Nicolás Straub almost 2 years

    I'm recieving an object of type System.Net.Http.HttpResponseMessage<List<T>>, how do I get the List<T>?

    I tried casting the content property and getting a value from the content property via its value property but nothing seems to work.

    Thanks for the help!

  • Mo Valipour
    Mo Valipour almost 11 years
    Just a note that you need to add a reference to System.Net.Http.Formatting