本文详细介绍了常见的HTTP状态码,包括200 OK、201 Created等成功响应,304 Not Modified等重定向响应,400 Bad Request、404 Not Found等客户端错误,以及500 Internal Server Error、502 Bad Gateway等服务器错误。
/**
* 200 OK
*/
public static final HttpResponseStatus OK = new HttpResponseStatus(200, "OK");
/**
* 201 Created
*/
public static final HttpResponseStatus CREATED = new HttpResponseStatus(201, "Created");
/**
* 202 Accepted
*/
public static final HttpResponseStatus ACCEPTED = new HttpResponseStatus(202, "Accepted");
/**
* 304 Not Modified
*/
public static final HttpResponseStatus NOT_MODIFIED = new HttpResponseStatus(304, "Not Modified");
/**
* 400 Bad Request
*/
public static final HttpResponseStatus BAD_REQUEST = new HttpResponseStatus(400, "Bad Request");
/**
* 404 Not Found
*/
public static final HttpResponseStatus NOT_FOUND = new HttpResponseStatus(404, "Not Found");
/**
* 408 Request Timeout
*/
public static final HttpResponseStatus REQUEST_TIMEOUT = new HttpResponseStatus(408, "Request Timeout");
/**
* 500 Internal Server Error
*/
public static final HttpResponseStatus INTERNAL_SERVER_ERROR =
new HttpResponseStatus(500, "Internal Server Error");
/**
* 501 Not Implemented
*/
public static final HttpResponseStatus NOT_IMPLEMENTED = new HttpResponseStatus(501, "Not Implemented");
/**
* 502 Bad Gateway
*/
public static final HttpResponseStatus BAD_GATEWAY = new HttpResponseStatus(502, "Bad Gateway");
/**
* 503 Service Unavailable
*/
public static final HttpResponseStatus SERVICE_UNAVAILABLE = new HttpResponseStatus(503, "Service Unavailable");
/**
* 504 Gateway Timeout
*/
public static final HttpResponseStatus GATEWAY_TIMEOUT = new HttpResponseStatus(504, "Gateway Timeout");
if (code < 100) {
reasonPhrase = "Unknown Status";
} else if (code < 200) {
reasonPhrase = "Informational";
} else if (code < 300) {
reasonPhrase = "Successful";
} else if (code < 400) {
reasonPhrase = "Redirection";
} else if (code < 500) {
reasonPhrase = "Client Error";
} else if (code < 600) {
reasonPhrase = "Server Error";
} else {
reasonPhrase = "Unknown Status";
}