Reputation: 261
We are trying to send GET or POST request using a resttemplate spring lib
Look like error Live Server throw error Local envirment working very well
Upvotes: 0
Views: 638
Reputation: 11906
I think you should add a "User-Agent" header to your request. You can either try to set a custom user agent value or use some value that identifies a browser.
Like-
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
headers.add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36");
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
Object response = restTemplate.exchange("https://test.prateek.com/tests.json", HttpMethod.GET,entity,Object.class);
Upvotes: 1