背景:如果是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; }