Ad

How To Fetch Url Api "http://terriblytinytales.com/test.txt" In Spring Boot

- 1 answer

I am using Rest Template :- TO fetch The data

@RestController
public class apicontroller {
    @Autowired
    public RestTemplate restTemplate;
   
    @RequestMapping(value="/movies",method = RequestMethod.GET,consumes = MediaType.TEXT_PLAIN)
    
    public List<Object> getobject(){

        Object[] movies=restTemplate.getForObject("http://terriblytinytales.com/test.txt",Object[].class);
        return Arrays.asList(movies);

    }


}

It is not fetching the data as its content type is text/plain What should i do to change Content type here

Ad

Answer

Text content can't be assigned to an array. Change Object[] to String.

String movies = restTemplate.getForObject("https://terriblytinytales.com/test.txt", String.class);
Ad
source: stackoverflow.com
Ad