How to read HttpResponseMessage content as text

后端 未结 3 2124
攒了一身酷
攒了一身酷 2021-01-01 09:00

I\'m using HttpResponseMessage class as a response from an AJAX call which is returning JSON data from a service. When I pause execution after the AJAX call comes back from

3条回答
  •  心在旅途
    2021-01-01 09:24

    You can use ReadAsStringAsync on the Content.

    var response = await client.SendAsync(request);
    var content = await response.Content.ReadAsStringAsync();
    

    Note that you usually should be using await - not .Result.

提交回复
热议问题