postMethod 返回值不全问题求助

xyer1987 2020-11-30 05:07:53
引入的包是:commons-codec-1.5.jar、commons-httpclient-3.0.1.jar、httpcore-4.2.4.jar

HttpClient client = new HttpClient();
String url="http://localhost:8089/public/getNameLists?entpName="+entpName+ "&orgCode=" +orgCode+ "&typeCode=" +typeCode+ "";
System.out.println("连接的url数据:"+url);
client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); //连接超时为5秒
client.getHttpConnectionManager().getParams().setSoTimeout(5000); //读取超时
PostMethod postMethod = new PostMethod(url);
postMethod.setRequestHeader("Content-Type", "application/json");

//设置参数编码为utf-8
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");

try {
//读取内容
int status = client.executeMethod(postMethod);

if (postMethod.getStatusCode() == HttpStatus.SC_OK) {

BufferedReader reader = new BufferedReader(new InputStreamReader(postMethod.getResponseBodyAsStream()));
StringBuffer stringBuffer = new StringBuffer();
String str = "";
while((str = reader.readLine())!=null){
stringBuffer.append(str);
}
String html=stringBuffer.toString();
System.out.println("返回来的数据:"+html);

}
} catch (Exception e) {
e.printStackTrace();
}finally{
//释放连接
postMethod.releaseConnection();
}

打印结果:返回来的数据:{"result":"1","tableName":"重大税收违法案件,"}
正确的结果:{"result":"1","tableName":"重大税收违法案件,工商吊销企业名单,"} tableName中缺少一个值,请问是怎么回事儿,因为项目中好多地方都用了这个包,所以不想换掉,请问如果不更换jar包 还有没有别的解决办法。。
...全文
5923 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyer1987 2020-12-02
  • 打赏
  • 举报
回复
引用 4 楼 KeepSayingNo 的回复:
HttpClient 应该可以直接拿到HttpResponse对象,直接从这个对象里面获取数据
请指点怎么弄,谢谢
xyer1987 2020-12-02
  • 打赏
  • 举报
回复
请指点怎么弄,谢谢
xyer1987 2020-12-01
  • 打赏
  • 举报
回复

apizza.net测试 返回结果是这样的,应该不会读取不全的。
xyer1987 2020-12-01
  • 打赏
  • 举报
回复
在谷歌的apizza.net测试 返回结果 没有换行业没有空格
KeepSayingNo 2020-12-01
  • 打赏
  • 举报
回复
HttpClient 应该可以直接拿到HttpResponse对象,直接从这个对象里面获取数据
爱可乐的钉子 2020-11-30
  • 打赏
  • 举报
回复
重大税收违法案件,工商吊销企业名单 两句话中间有没有空格 换行之类的,.readLine()读取到空格换行就会停止。

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧