FileDocCategorySizeDatePackage
BasicResponseHandler.javaAPI DocAndroid 1.5 API3147Wed May 06 22:41:10 BST 2009org.apache.http.impl.client

BasicResponseHandler

public class BasicResponseHandler extends Object implements ResponseHandler
A {@link ResponseHandler} that returns the response body as a String for successful (2xx) responses. If the response code was >= 300, the response body is consumed and an {@link HttpResponseException} is thrown. If this is used with {@link org.apache.http.client.HttpClient#execute( org.apache.http.client.methods.HttpUriRequest, ResponseHandler), HttpClient may handle redirects (3xx responses) internally.
author
Oleg Kalnichevski
version
$Revision: 677240 $
since
4.0

Fields Summary
Constructors Summary
Methods Summary
public java.lang.StringhandleResponse(org.apache.http.HttpResponse response)
Returns the response body as a String if the response was successful (a 2xx status code). If no response body exists, this returns null. If the response was unsuccessful (>= 300 status code), throws an {@link HttpResponseException}.

        StatusLine statusLine = response.getStatusLine();
        if (statusLine.getStatusCode() >= 300) {
            throw new HttpResponseException(statusLine.getStatusCode(),
                    statusLine.getReasonPhrase());
        }

        HttpEntity entity = response.getEntity();
        return entity == null ? null : EntityUtils.toString(entity);