工具类代码如下,分页100的情况下没什么问题,分页1000,就会在请求前几页的时候出现json异常,发现返回的数据被截断,换个工具类就没问题了,求解?
public String doGet(String url) throws UnsupportedEncodingException {
HttpClient client = new HttpClient(); // 实例化httpClient
client.getHttpConnectionManager().getParams()
.setConnectionTimeout(TIME_OUT);
client.getHttpConnectionManager().getParams().setSoTimeout(TIME_OUT);
HttpMethod method = new GetMethod(url); //
String responseContent = "";
try {
client.executeMethod(method); // 执行
InputStream jsonStr;
jsonStr = method.getResponseBodyAsStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int i = -1;
while ((i = jsonStr.read()) != -1) {
baos.write(i);
}
responseContent = baos.toString();
jsonStr.close();
baos.close();
method.releaseConnection();
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (responseContent != null) {
// 用默认字符编码解码字符串。
byte[] bs = responseContent.getBytes();
// 用新的字符编码生成字符串
return new String(bs, "UTF-8");
}
return null;
}