I am trying to get Apache HttpClient to fire an HTTP request, and then display the HTTP response code (200, 404, 500, etc.) as well as the HTTP response body (text string).
Fluent facade API:
Response response = Request.Get(uri)
.connectTimeout(MILLIS_ONE_SECOND)
.socketTimeout(MILLIS_ONE_SECOND)
.execute();
HttpResponse httpResponse = response.returnResponse();
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
// 响应内容编码自适应?(好像没那么智能)
String responseContent = EntityUtils.toString(
httpResponse.getEntity(), StandardCharsets.UTF_8.name());
}