Java是否有完整的HTTP响应代码枚举? [英] Does Java have a complete enum for HTTP response codes?
问题描述
我想知道在某个标准Java类库中是否存在枚举类型,它定义了所有有效HTTP响应代码的符号常量。它应该支持转换为/从相应的整数值转换。
I'm wondering if there is an enum type in some standard Java class library that defines symbolic constants for all of the valid HTTP response codes. It should support conversion to/from the corresponding integer values.
我正在调试一些使用javax.ws.rs.core.Response.Status的Java代码。它有效,但它只定义了大约一半的有效HTTP响应代码。
I'm debugging some Java code that uses javax.ws.rs.core.Response.Status. It works, but it only defines about half of the valid HTTP response codes.
推荐答案
我认为没有一个是完整的在标准的Java类中; HttpURLConnection
缺少相当多的代码,例如 HTTP 100 / Continue
。但是,Apache Commons中有一个完整的列表: org.apache.commons.HttpClient.HttpStatus
。
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 Commons, though: org.apache.commons.HttpClient.HttpStatus
.
更新: Apache Commons HttpClient是报废。有关状态代码列表,请使用 < Apache HttpComponents中的strong> org.apache.http.HttpStatus
。
Update: Apache Commons HttpClient is end of life. For a list of status codes, use org.apache.http.HttpStatus
in Apache HttpComponents.
这篇关于Java是否有完整的HTTP响应代码枚举?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!