C# get api response for debugging
I am trying to get api response based on apiurl as parameter using c# code as below. Things are working fine but I am unable to debug and see the final json response. Is there any other option to get the api response to a variable to debug and check final complete response. Will this approach of getting api json has any issues?
[HttpGet("[action]")]
public async Task GET(string url)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization", BearerToken);
try
{
WebResponse response = request.GetResponse();
using (Stream responseStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.UTF8);
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
WebResponse errorResponse = ex.Response;
using (Stream responseStream = errorResponse.GetResponseStream())
{
StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.GetEncoding("utf-8"));
String errorText = reader.ReadToEnd();
}
throw;
}
}