cn.net.wanmo.apache.http.HttpResult Maven / Gradle / Ivy
package cn.net.wanmo.apache.http;
import org.apache.http.*;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.util.Objects;
public class HttpResult {
protected HttpResponse response;
public HttpResult() {
}
public HttpResult(HttpResponse response) {
this.response = response;
}
public HttpResponse getResponse() {
return response;
}
public void setResponse(HttpResponse response) {
this.response = response;
}
public Integer statusCode() {
return response.getStatusLine().getStatusCode();
}
public Header[] header() {
return response.getAllHeaders();
}
public String body() {
String s = "";
try {
HttpEntity entity = response.getEntity();
if (Objects.nonNull(entity)) {
s = EntityUtils.toString(entity, Consts.UTF_8);
EntityUtils.consume(entity);
}
return s;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public boolean isOk() {
return HttpStatus.SC_OK == statusCode();
}
}