【发布时间】:2019-08-23 14:22:28
【问题描述】:
我想使用 restTemplate 来使用 html 响应并将该响应重新运行到我的 html 中,这样我就可以将这些内容添加到我的 html 页面,但是遇到错误尝试了很多替代方法,但没有运气
我想使用每种类型的响应并通过 ajax 将其原样返回到我的 html/jsp 并在 div 中呈现该内容。
HTML (ajax call) --- Spring MVC (rest call to 3rd party) --- 应用程序返回 html
代码
@RequestMapping(value = "/xyz-service/**", method = {RequestMethod.GET, RequestMethod.PUT},produces="application/json;charset=UTF-8")
public Object mirrorRest(HttpServletRequest request) {
String url = request.getRequestURI();
return restTemplate.getForObject("http://xyz-service:8080"+url , String.class);
}
我能够调用我的服务方法,将 html 重新调整为响应但得到错误
"Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.String] and content type [text/html;charset=UTF-8]"
]
【问题讨论】:
-
你检查过这个线程stackoverflow.com/questions/44176335/…吗?