android-lite-http处理http异常返回时的content数据读取

来源:互联网 发布:汉仪字体淘宝侵权 编辑:程序博客网 时间:2024/06/14 20:45

背景:如果是http异常返回,android-lite-http返回的信息里面没有response的content数据,需要简单添加点东西


1、修改类HttpException.java 增加变量


private String content;public String getContent() {    return content;}public void setContent(String content) {    this.content = content;}

2、修改类HttpUrlClient.java


//            } else if (statusCode <= 499) {//                // 客户端被拒//                throw new HttpServerException(httpStatus);//            } else if (statusCode < 599) {//                // 服务器有误//                throw new HttpServerException(httpStatus);//            }            } else if (statusCode  < 599) {                // 客户端被拒/服务器有误                String charSet = getCharsetByContentType(response.getContentType(), request.getCharSet());                response.setCharSet(charSet);                BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, charSet));                String temp = null;                StringBuilder content = new StringBuilder();                while ((temp = reader.readLine()) != null) {                    content.append(temp);                }                inputStream = null;                HttpServerException httpServerException = new HttpServerException(httpStatus);                httpServerException.setContent(content.toString());                throw httpServerException;            }



0 0
原创粉丝点击