Reputation: 18746
I want to get the content of the 500 error: neither appears to let me do so, exceptions are thrown:
using(var wc = new WebClient()){
wc.DownloadString(address).Dump();
}
using(var wc = new HttpClient())
{
var result = await wc.GetStringAsync(address);
result.Dump();
}
and yes address is a valid address "http://foo.azurewebsites.net/Account/Login"
and I have tried them each individually.
How do I read the content/response of the 500 error from the asp.net site?
Upvotes: 1
Views: 3447
Reputation: 18746
This shows the rest of the details of how you might read the Response
property usr referred to
void Main()
{
try
{
using(var wc = new WebClient()){
wc.DownloadString(Util.ReadLine("sitename?")).Dump("success");
}
}
catch (WebException ex)
{
string response;
using(var stream=ex.Response.GetResponseStream())
using(var sr = new StreamReader(stream))
{
response=sr.ReadToEnd();
}
response.Dump("error");
}
}
Upvotes: 2
Reputation: 171218
A WebException
has a Response
property. It works like any other response. You can read its contents and the exact status code.
Upvotes: 2