我正在尝试捕获我的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();
Listarameters);
byte[] resultByteArr = (byte[])result;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。