Hi all,
I have a servlet with this response:
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "No Access");
I want to connect this servelt with:
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
And read the error message, but just the custom String ("No Access"). Is it possible to obtain just this string?
I've tried with:
urlConn.getResponseMessage()
but i get the generic error message (Unauthorized) instead of the custom one.
With:
urlConn.getErrorStream();
I get the whole HTML error message generated by the server, so I'd had to parse it, which is not a good solution.
Any idea?
Thank you in advance.