码上敲享录 > java入门知识分享 > java的http接口传输对象

java的http接口传输对象

上一章章节目录下一章 2019-11-02已有1372人阅读 评论(0)

java的http接口传输对象


解决方法:

对象要实现Serializable接口。

1.服务端

JasperPrint jasperPrint = null;//你的对象

response.setContentType("application/json; charset=UTF-8");

ObjectOutputStream out = new ObjectOutputStream(response.getOutputStream());

out.writeObject(jasperPrint);

out.close();


2.客户端

          URL urlObj = new URL(url);

          HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();

          // 连接超时

           conn.setDoInput(true);

           conn.setDoOutput(true);

           conn.setConnectTimeout(25000);

           // 读取超时 --服务器响应比较慢,增大时间

           conn.setReadTimeout(25000);

           conn.setRequestMethod("POST");

           conn.connect();

           ObjectInputStream objectInputStream = new ObjectInputStream((InputStream) conn.getContent());

           JasperPrint jasperPrint = (JasperPrint) objectInputStream.readObject();

           // 断开连接

           conn.disconnect();


向大家推荐《Activiti工作流实战教程》:https://xiaozhuanlan.com/activiti
0

有建议,请留言!

  • *您的姓名:

  • *所在城市:

  • *您的联系电话:

    *您的QQ:

  • 咨询问题:

  • 提 交