How to read HttpResponseMessage content as text

The textual representation of the response is hidden in the Content property of the HttpResponseMessage class. Specifically, you get the response like this:

response.Content.ReadAsStringAsync();

Like all modern Async methods, ReadAsStringAsync returns a Task. To get the result directly, use the Result property of the task:

response.Content.ReadAsStringAsync().Result;

Note that Result is blocking. You can also await ReadAsStringAsync().

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)