How to get the response from API using rest template over proxy network without setting proxy details?
Example: http://gturnquist-quoters.cfapps.io/api/random. I am getting response if opening the browsers, I am trying to consume the API through proxy network but I don't want to use proxyHost and proxyPort in code, getting error : Connection timed out: connect; nested exception is java.net.ConnectException: Connection timed out: connect
public class RestWithoutProxy {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
RestTemplate restTemplate = new RestTemplate();
String url="http://gturnquist-quoters.cfapps.io/api/random";
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
System.out.println("... calling api");
try{
ResponseEntity<String> response = restTemplate
.exchange(url, HttpMethod.GET, entity, String.class);
System.out.println("response: "+ response.getBody());
}catch(HttpStatusCodeException ex){
int statusCode = ex.getStatusCode().value();
System.out.println("error code: "+statusCode+"\n"+ex.getMessage());
}catch (Exception ex) {
System.out.println("......inside rest exception\n"+ ex.getMessage());
}
}
}
Code is not working if using office network where proxy and firewall is enabled, but same code is working if using open network