BasicResponseHandler returns only your data if a success code (2xx) was returned. However, you can easily write your own ResponseHandler to always return the response body as a String , for example.
ResponseHandler<String> responseHandler = new ResponseHandler<String>() { @Override public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException { return EntityUtils.toString(response.getEntity()); } };
Alternatively, you can use another overloaded execution method on HttpClient that does not require a ResponseHandler and returns an HttpResponse directly. Then call EntityUtils.toString(response.getEntity()) in the same way.
To get the response status code, you can use HttpResponse.getStatusLine().getStatusCode() and compare it with one of the static ints in the HttpStatus class. For example. code '403' is equal to HttpStatus.SC_FORBIDDEN . You can take certain actions specific to your application, depending on the status code returned.
antonyt
source share