阅读Java / Groovy中的多部分/混合响应 [英] Read multipart/mixed response in Java/Groovy

查看:208
本文介绍了阅读Java / Groovy中的多部分/混合响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个需要解析的http请求的multipart / mixed响应。答复的一部分是我需要保存到磁盘的pdf文件。是否有任何图书馆可以为我做这件事?

这是我在groovy中做的事情。需要java邮件库:

  // ...从响应中获取读者,可以在http.request中使用response.success回调
ByteArrayDataSource ds = new ByteArrayDataSource(new ReaderInputStream(reader),multipart / mixed);
MimeMultipart multipart = new MimeMultipart(ds);
BodyPart part = multipart.getBodyPart(1);
file =新建文件('/../../ path / filename.pdf')
文件<< part.content


I am getting a "multipart/mixed" response to an http request that I need to parse. One part of the response is a pdf file which I need to save to disk. Is there any library that will do this for me?

解决方案

Here is what I did in groovy. Needed java mail library:

//... get reader from response, can use response.success callback in http.request
ByteArrayDataSource ds = new ByteArrayDataSource(new ReaderInputStream(reader), "multipart/mixed");
MimeMultipart multipart = new MimeMultipart(ds);
BodyPart part = multipart.getBodyPart(1);
file = new File('/../../path/filename.pdf')
file << part.content

这篇关于阅读Java / Groovy中的多部分/混合响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆