Example usage for org.apache.commons.httpclient HttpMethodBase getResponseBody

List of usage examples for org.apache.commons.httpclient HttpMethodBase getResponseBody

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethodBase getResponseBody.

Prototype

@Override
public byte[] getResponseBody() throws IOException 

Source Link

Document

Returns the response body of the HTTP method, if any, as an array of bytes.

Usage

From source file:org.zend.sdklib.internal.target.ApiKeyDetector.java

private String executeGetApiKeys(String url, Map<String, String> cookies) throws SdkException {
    HttpClient client = new HttpClient();
    HttpMethodBase method = createGetRequest(url, new HashMap<String, String>());
    setCookies(method, cookies);/*from w  w  w . j  a v  a  2  s .  c  o m*/
    method.setRequestHeader("X-Accept", //$NON-NLS-1$
            "application/vnd.zend.serverapi+json;version=1.3;q=1.0"); //$NON-NLS-1$
    method.setRequestHeader("X-Request", "JSON"); //$NON-NLS-1$ //$NON-NLS-2$
    if (method != null) {
        int statusCode = -1;
        try {
            statusCode = client.executeMethod(method);
            if (statusCode == 200) {
                String responseContent = new String(method.getResponseBody());
                return responseContent;
            }
        } catch (IOException e) {
            throw new SdkException(e);
        } finally {
            method.releaseConnection();
        }
    }
    return null;
}