加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何使用RestTemplate从服务器接收应用程序/ pdf响应

发布时间:2020-12-15 01:48:25 所属栏目:大数据 来源:网络整理
导读:我正在尝试捕获我的java客户端代码发出的HTTP请求的响应.响应的内容类型为application / pdf.在日志中我可以看到服务器发送了响应 Object result = getRestTemplate().postForObject(urlString,formDataHttpEntity,returnClassObject,parametersMapStringStr

我正在尝试捕获我的java客户端代码发出的HTTP请求的响应.响应的内容类型为application / pdf.在日志中我可以看到服务器发送了响应

Object result = getRestTemplate().postForObject(urlString,formDataHttpEntity,returnClassObject,parametersMapStringString);

我得到以下JUnit错误:

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type
[java.lang.Object] and content type [application/pdf]

我需要做些什么来克服这个问题?我的最终目标是将其放在byte []中并将其推送到blob类型的DB表字段中

注意:我从服务器获得以下响应头

HTTP/1.1 200 OK Cache-Control: max-age=0,must-revalidate
Content-Disposition: attachment; filename=”Executive Summary.PDF”
Content-Type: application/pdf

最佳答案
谢谢托马斯的工作.

我将ByteArrayHttpMessageConverter添加到RestTemplate并且它有效.

我添加的代码:

ByteArrayHttpMessageConverter byteArrayHttpMessageConverter = new ByteArrayHttpMessageConverter();

List

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读