I have a server running a WebAPI service, on the client I run the call to a POST URL like this:
try
{
HttpWebRequest request;
request = (HttpWebRequest)WebRequest.Create(URL);
request.Method = "POST";
request.Proxy = null;
request.ContentType = "application/json";
byte[] dataStream = Encoding.UTF8.GetBytes(DATA);
Stream newStream = request.GetRequestStream();
newStream.Write(dataStream, 0, dataStream.Length);
newStream.Close();
request.GetResponse();
}
catch (Exception ex)
{
//QUERO LER O ERRO AQUI
}
On the server I'll do the following:
try
{
...
}
catch (Exception ex)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError,ex);
}
The problem is that in the client it comes a exception
saying that it took error 500, I know that exception
does not "come" from the server, which is generated in the client, but I would like to know how I get the inner
all generated in CreateErrorResponse