在RestTemplate定义Proxy
SimpleClientHttpRequestFactory clientHttpReq = new SimpleClientHttpRequestFactory();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("your.proxy.server", 8080));
clientHttpReq.setProxy(proxy);
RestTemplate restTemplate = new RestTemplate(clientHttpReq);
String tt = restTemplate.getForObject("http://baike.baidu.com/",String.class);
System.out.println(tt);
通过System properties定义Proxy
Properties props = System.getProperties();
props.put("http.proxyHost", "your.proxy.server");
props.put("http.proxyPort", "8080");
RestTemplate restTemplate = new RestTemplate();
String tt = restTemplate.getForObject("http://baike.baidu.com/",String.class);
System.out.println(tt);
Https的代理也设置为HTTPS
Properties props = System.getProperties();
props.put("https.proxyHost", "your.proxy.server");
props.put("https.proxyPort", "8080");
RestTemplate restTemplate = new RestTemplate();
String tt = restTemplate.getForObject("https://baike.baidu.com/",String.class);
System.out.println(tt);