import org.apache.http.HttpResponse; import org.apache.http.StatusLine; import org.apache.http.client.HttpClient; class Demo { // Helper static int range(final int n) { return n / 100 * 100; } public static final void main(String []args) { // ... make client and request ... HttpResponse response = client.execute(request); StatusLine sl = response.getStatusLine(); // GET THE STATUS int statusCode = sl.getStatusCode(); // statusCode will be the familiar HTTP codes like 200 for success // and 404 for page not found. if (range(statusCode) != 200) { // Failed } } }
Programming Tips - Java: Get the status from an HttpResponse
Date: 2013dec18
Update: 2025sep27
Language: Java
Library: Apache HTTP
Q. Java: Get the status from an HttpResponse
A. Its shown here in an incomplete example: