Dave's Brain

Browse - Programming Tips - How do I get the status from an HttpResponse ?

Date: 2013dec18
Language: Java

Q.  How do I get the status from an HttpResponse ?

A.
HttpResponse response = client.execute(request); StatusLine sl = response.getStatusLine(); int statusCode = sl.getStatusCode(); // statusCode will be the familiar HTTP codes like 200 for success // and 404 for page not found. // Do NOT do this: if (statusCode != 200) { // This is bad because there are other ways a page can succeed. return false; }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.