All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.turbomanage.httpclient.HttpResponse Maven / Gradle / Ivy

package com.turbomanage.httpclient;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.List;
import java.util.Map;

/**
 * Minimal representation of the raw HTTP response copied from {@link HttpURLConnection}. 
 * 
 * @author David M. Chandler
 */
public class HttpResponse {
    
    private int status;
    private String url;
    private Map> headers;
    private byte[] body;
    
    public HttpResponse(HttpURLConnection urlConnection, byte[] body) {
        try {
            this.status = urlConnection.getResponseCode();
            this.url = urlConnection.getURL().toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        this.headers = urlConnection.getHeaderFields();
        this.body = body;
    }
    
    public int getStatus() {
        return status;
    }
    
    public String getUrl() {
        return url;
    }

    public Map> getHeaders() {
        return headers;
    }
    
    public byte[] getBody() {
        return body;
    }

    public String getBodyAsString() {
        if (body != null) {
            return new String(body);
        }
        return null;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy