Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Java have a complete enum for HTTP response codes?

Tags:

java

http

People also ask

How do you handle a 202 response in Java?

If you receive a 202 it means the extraction has not yet completed, you must wait, and then repeat the GET query to the location URL, until you receive a 200 OK.

Which series will the HTTP response code?

HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes: Informational responses ( 100 – 199 ) Successful responses ( 200 – 299 )

How do I get HTTP body response?

To get the response body as a string we can use the EntityUtils. toString() method. This method read the content of an HttpEntity object content and return it as a string. The content will be converted using the character set from the entity object.


I don't think there's one that's complete in the standard Java classes; HttpURLConnection is missing quite a few codes, like HTTP 100/Continue.

There's a complete list in the Apache HttpComponents, though:
org.apache.http.HttpStatus (replaced org.apache.commons.HttpClient.HttpStatus from Apache Http Client, which reached end of life)


The Interface javax.servlet.http.HttpServletResponse from the servlet API has all the response codes in the form of int constants names SC_<description>. See http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html


Well, there are static constants of the exact integer values in the HttpURLConnection class


If you're using Spring, the 3.x release has what your looking for: http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/http/HttpStatus.html