美文网首页
Spring下使用Proxy发消息

Spring下使用Proxy发消息

作者: 金琥 | 来源:发表于2018-09-29 15:24 被阅读14次

在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);

相关文章

网友评论

      本文标题:Spring下使用Proxy发消息

      本文链接:https://www.haomeiwen.com/subject/zrfboftx.html