I am trying to download text/csv file from one of the Salesforce GET endpoint using Spring RestTemplate.
I am getting 204 no-content when trying from code. While I am trying to hit the same endpoint with from Postman (Send and download) its working fine.
I am using the below code :
HttpHeaders headers=new HttpHeaders();
headers.setAccept(Mediatype.APPLICATION_OCTET_STREAM);
headers.add("Authorization","");
HttpEntity<String> entity=new HttpEntity<>(headers);
ResponseEntity<byte[]>
response=template.build.exchange(url,HttpMethod.GET,entity,byte.class);
System.out.println(response);
To my surprise, when I am debugging the application and giving a debug point on the line where the GET call is made, the response is coming properly.
Looks like some buffering is required while calling the GET endpoint.
I have tried to use BufferingClientHttpRequestFactory like below :
ClientHttpRequestFactory factory=new BufferingClientHttpRequestFactory(new
HttpComponentsClientHttpRequestFactory);
RestTemplate template=new RestTemplate (factory);
Even with the above am getting the same 204 content.