1

I am making a call to Web API from my Console App. I get HttpResponseMessage as the response. I am unable to read that message content.

I tried

   var loginResult = await response.Content.ReadAsAsync<loginresult>(new List<MediaTypeFormatter> { new JsonMediaTypeFormatter() });

Visual studio complains that ReadAsAsync doesn't exist and also MediaTypeFormatter doesn't exist.

But it makes sense why it's not working, because It uses MediaFormatters which are specific to MVC. ReadAsAsync also doesn't support console apps.

How do i read HTTPResponseMessage content in Console App ?

4

1 回答 1

1

我相信您缺少对System.Net.Http.Formatting程序集的引用。你可以在Nuget上得到它。

这是ReadAsAsync<T> 文档

于 2017-02-09T15:45:15.873 回答