Getting content/message from HttpResponseMessage

后端 未结 8 2208
抹茶落季
抹茶落季 2020-12-01 00:18

I\'m trying to get content of HttpResponseMessage. It should be: {\"message\":\"Action \'\' does not exist!\",\"success\":false}, but I don\'t know, how to get

8条回答
  •  离开以前
    2020-12-01 01:07

    Try this, you can create an extension method like this:

        public static string ContentToString(this HttpContent httpContent)
        {
            var readAsStringAsync = httpContent.ReadAsStringAsync();
            return readAsStringAsync.Result;
        }
    

    and then, simple call the extension method:

    txtBlock.Text = response.Content.ContentToString();
    

    I hope this help you ;-)

提交回复
热议问题