I have a java servlet that throws a custom error 403 (Forbidden) when the user authenticates with an incorrect user/password. Java Servlet code:
response.sendError(response.SC_FORBIDDEN, "Login Error: wrong password!");
On the .net side I catch the error via a WebException but when I interrogate the contents of the WebException I don't see the Login Error custom message unless I do the following:
catch (WebException e)
{
HttpWebResponse resp = e.Response as HttpWebResponse;
StreamReader reader = new StreamReader(resp.GetResponseStream());
string respStr = reader.ReadToEnd();
reader.Close();
}
The problem with this is that respStr is the HTML string which I would then have to parse to get the "Login Error: wrong password!" string. If I just do a e.Message all I see is "The remote server returned an error: (403) Forbidden."
Is there an easier way to get the custom message?