'Consume Html response using restTemplate

I want to consume html response using restTemplate and rerun that response to my html so i can add those content to my html page but getting below error tried so many alternatives but not luck

I want to consume every type of response and return that as it is to my html/jsp via ajax and render that content in a div.

HTML (ajax call) --- Spring MVC (rest call to 3rd party) --- application returns html

Code

@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);
    }

I am able to invoke my serive method that retuning html as respose but getting error

"Could not extract response: no suitable HttpMessageConverter found for response type [class java.lang.String] and content type [text/html;charset=UTF-8]"
]


Solution 1:[1]

No you can't. An HTML page is not a json object: REST template is designed to consume RestServices. You should use a URLConnection from jdk

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ivan.rosina