Code example for HttpResponse

Methods: getHeadersgetStatusLine

0
    public static HttpResponseHeaders fromResponse(HttpResponse response, HttpUriRequest request) {
        LogUtils.logd(TAG, "[fromResponse] BEGIN");
 
        HttpResponseHeaders headers = new HttpResponseHeaders();
 
        headers.mResponseCode = response.getStatusLine().getStatusCode();
        headers.mStatusLine = response.getStatusLine().toString();
        headers.mContentEncoding = getResponseHeaderFirstValue(response, HEADER_CONTENT_ENCODING);
        try { 
            headers.mContentLength = Integer.parseInt(
                    getResponseHeaderFirstValue(response, HEADER_CONTENT_LENGTH));
        } catch (NumberFormatException e) {
            headers.mContentLength = -1;
        } 
        headers.mContentType = getResponseHeaderFirstValue(response, HEADER_CONTENT_TYPE);
        headers.mLastModified = getResponseLastModified(response);
        headers.mLastModifiedUtc = getResponseHeaderFirstValue(response, HEADER_LAST_MODIFIED);
        headers.mETag = getResponseHeaderFirstValue(response, HEADER_ETAG);
        headers.mResponse = response;
        headers.mRequest = request;
 
        return headers;
    } 
 
    private static String getResponseHeaderFirstValue(HttpResponse response, String headerName) {
        Header[] h = response.getHeaders(headerName);
        if (h.length > 0) return h[0].getValue();
        return null; 
    } 
 
    private static long getResponseLastModified(HttpResponse response) {
Stop searching for code, let great code find you!  Add Codota to your java IDE