I have tried the below answer, but all I get is an empty string.
WebException how to get whole response with a body?
I have tested hitting the endpoint through postman, and I get the json response (error response) as I expect. But when I try and hit that endpoint in .net, the response doesn't seem to contain the JSON. The above questions answer results in an empty string.
catch (WebException ex)
{
var resp = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
dynamic obj = JsonConvert.DeserializeObject(resp);
var messageFromServer = obj.error.message;
return messageFromServer;
}
And when I try to just return the ReadToEnd() string, it's empty. Just "".
But as stated before, the endpoint I'm hitting is returning the JSON correctly.
{
"Message" : "The number could not be found"
}