weixin_36165756
2018-10-23 02:57
采纳率: 0%
浏览 2.5k

调用别人的rest接口,本地测试返回不乱码,运行在tomcat上会出现部分中文乱码,跪求大神

private ResResult getResResult(HttpURLConnection httpURLConnection, String policyStatusJson)
{
BufferedReader bufferedReader = null;
DataOutputStream dataOutputStream = null;
ResResult res = null;
try
{
if (policyStatusJson != null)
{
dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
dataOutputStream.write(policyStatusJson.getBytes());
}
bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
StringBuffer resultBuf = new StringBuffer("");
String line = null;
while ((line = bufferedReader.readLine()) != null) {
line = new String(line.getBytes(), "utf-8");
resultBuf.append(line);
}
res = (ResResult)new Gson().fromJson(resultBuf.toString(), ResResult.class);
httpURLConnection.disconnect();

  return res;
}
catch (IOException e)
{
  e.printStackTrace();
}
finally
{
  try
  {
    if (bufferedReader != null) {
      bufferedReader.close();
    }
    if (dataOutputStream != null) {
      dataOutputStream.close();
    }
  }
  catch (IOException e)
  {
    e.printStackTrace();
  }
}
return res;

}

==========本地测试结果============

最新更新时间:2018-10-15 16:48:29.31 内容是:保单状态1

===========tomcat服务运行结果==========

:�?新更新时间:2018-10-15 16:48:29.31 内容是:保单状�??1;

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

6条回答 默认 最新

  • crazydddfz 2018-10-23 03:00
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题