My application gets most of its data from a php web server.
My problem is when the server return errors.
The errors are not HTML pages, but simple strings.
for example:
ERROR001
could stand for invalid name.
here is my code:
String responseBody = null;
URL url = new URL(strUrl);
URLConnection connection;
connection = url.openConnection();
connection.setUseCaches(false);
InputStream isResponse = (InputStream) connection.getContent(); // on errors I get IOException here
responseBody = convertStreamToString (isResponse);
When I use it, I get IOException on connection.getContent();
I also tried:
HttpGet getMethod = new HttpGet(url);
String responseBody = null;
responseBody = mClient.execute(getMethod,mResponseHandler); // on errors I getClientProtocolException
but I get getClientProtocolException on mClient.execute
Any ideas how I could read a result like ERROR001 into a string?
The problem is that on error, the Http header is HTTP Error 500 (Internal server error).
To read the error content I used the following code: