时代Java,与您同行!
关注微信公众号,关注前沿技术,微信搜索:nowjava或时代Java,也可点击这里扫码关注
时代Java
首页
集册
文章
实例
项目
快讯
时代+
手册
下载
Jar查找
登录
注册
Java 获取HTTP代码消息
Java 获取HTTP代码消息
欢马劈雪
工程师 (已认证)
原创分享签约作者
发表于
实例源码
订阅
447
查看 / 运行 实例源码
获取HTTP代码消息
实例源码:
源代码:
执行
执行中...
/**来自 N o w J a v a . c o m**/ //package com.nowjava; public class Main { public static void main(String[] argv) throws Exception { int httpCode = 2; System.out.println(getCodeMessage(httpCode)); } public static String getCodeMessage(int httpCode) { if (httpCode < 400) return getlowCodeMessage(httpCode); return getHightCodeMessage(httpCode); } /* 来自 *nowjava.com - 时代Java*/ private static String getlowCodeMessage(int httpCode) { String codeMessage; switch (httpCode) { case 100: codeMessage = "100:Continue"; break; case 101: codeMessage = "101:Switching Protocols"; break; case 102: codeMessage = "102:Processing"; break; case 200: codeMessage = "200:OK"; break; case 201: codeMessage = " 201:Created"; break; case 202: codeMessage = "202:Accepted"; break; case 203: codeMessage = "203:Non-Authoritative Information"; break; case 204: codeMessage = "204:No Content"; break; case 205: codeMessage = " 205:Reset Content"; break; case 206: codeMessage = "206:Partial Content"; break; case 207: codeMessage = "207:Multi-Status"; break; case 300: codeMessage = "300:Multiple Choices"; break; case 301: codeMessage = " 301:Moved Permanently"; break; case 302: codeMessage = "302:Move temporarily"; break; case 303: codeMessage = "303:See Other"; break; case 304: codeMessage = "304:Not Modified"; break; case 305: codeMessage = " 305:Use Proxy"; break; case 306: codeMessage = "306:Switch Proxy"; break; case 307: codeMessage = "307:Temporary Redirect"; break; default: codeMessage = ""; break; } return codeMessage; } private static String getHightCodeMessage(int httpCode) { String codeMessage; switch (httpCode) { case 400: codeMessage = "400:Bad Request"; break; case 401: codeMessage = "401:Unauthorized"; break; case 402: codeMessage = "402:Payment Required"; break; case 403: codeMessage = "403:Forbidden"; break; case 404: codeMessage = "404:Not Found"; break; case 405: codeMessage = "405:Method Not Allowed"; break; case 406: codeMessage = "406:Not Acceptable"; break; case 407: codeMessage = "407:Proxy Authentication Required"; break; case 408: codeMessage = "408:Request Timeout"; break; case 409: codeMessage = "409:Conflict"; break; case 410: codeMessage = "410:Gone"; break; case 411: codeMessage = "411:Length Required"; break; case 412: codeMessage = "412:Precondition Failed"; break; case 413: codeMessage = "413:Request Entity Too Large"; break; case 414: codeMessage = "413:Request-URI Too Long"; break; case 415: codeMessage = "415:Unsupported Media Type"; break; case 416: codeMessage = "416:Requested Range Not Satisfiable"; break; case 417: codeMessage = "417:Expectation Failed"; break; case 421: codeMessage = "421:There are too many connections from your internet address"; break; case 422: codeMessage = "422:Unprocessable Entity"; break; case 423: codeMessage = "423:Locked"; break; case 424: codeMessage = "424:Failed Dependency"; break; case 425: codeMessage = "425:Unordered Collection"; break; case 426: codeMessage = "426:Upgrade Required"; break; case 449: codeMessage = "449:Retry With"; break; case 500: codeMessage = "500:Internal Server Error"; break; case 501: codeMessage = "501:Not Implemented"; break; case 502: codeMessage = "502:Bad Gateway"; /**代码未完, 请加载全部代码(NowJava.com).**/
编辑/阅读全部代码
执行结果:
本文系作者在时代Java发表,未经许可,不得转载。如有侵权,请联系nowjava@qq.com删除。
编辑于
2020-03-26 09:23:27
2020-03-26 09:23:27
分享
分享文章到朋友圈
分享文章到 QQ
分享文章到微博
复制文章链接到剪贴板
扫描二维码
关注时代Java
实例源码
实例源码
订阅
订阅专栏
Java 判断文件是否为文本文件及获取文件编码格式的方法实例
bootstrap 实例演示下拉菜单(Dropdown)插件用法。
HashSet、LinkedHashSet、TreeSet类存储元素的自动排序规则实例测试
html css 对于 body和h1设置的实例源码
Java 获取在线网页的源代码
Java HashSet添加、迭代输出字符串的完整示例代码
Java 随机整数数组
html css 设置背景图片定位并且不平铺
扫描二维码
关注时代Java
返回顶部