如何在Java中将HTTP状态代码转换为文本? [英] How to convert HTTP status code into text in Java?

查看:426
本文介绍了如何在Java中将HTTP状态代码转换为文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Java中将HTTP状态代码转换为其文本表示形式?我的意思是这种转换有任何现有的实现。到目前为止,我发现的最好的是 java.ws.rs.core.Response.Status #fromStatusCode(),它只转换所有状态的有限子集。

How can I convert HTTP status code to its text representation, in Java? I mean are there any existing implementations of such a conversion. The best I've found so far is java.ws.rs.core.Response.Status#fromStatusCode(), which converts only a limited subset of all statuses.

推荐答案

Apache HttpComponents 有一个(旧式)枚举类,它执行此操作:

Apache HttpComponents has an (old-style) enum class which does this:

http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/ httpclient / HttpStatus.html

您可以使用枚举实例作为参数调用其 getStatusText 方法获取状态代码的文本表示。

You can call itsgetStatusText method with an enum instance as the argument to get the text representation of a status code.

Maven依赖是:

<dependency>
  <groupId>commons-httpclient</groupId>
  <artifactId>commons-httpclient</artifactId>
  <version>3.1</version>
</dependency>

这篇关于如何在Java中将HTTP状态代码转换为文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆