HttpClientBuilder中设置代理服务器 - TCoolsIT

20-04-03 banq

使用Spring Boot中RestTemplate/WebserviceTemplate时,如果正在使用代理,使用自定义HttpClient访问,默认情况下,HttpClientBuilder中未设置这些代理服务器。

设置代理服务器,请添加以下内容:

RequestConflg.Builder requestBuiAder = RequestConfi_g.custom();
String httpProxyHost = //read from properties http(s).proxyHost;
String httpProxyPort = //read from properties http(s).proxyPort;
//add null checks/property validation, etc.
HttpHost host = new HttpHost(httpProxyHost, Integer.parselnt(httpProxyPort 
requestBuUder. setProxy( host);
CloseableHttpCllent httpClientBullder = HttpCllentBullder.create()
            . setDefaultRequestConf'lgf requestBuUder.buUd())
            .buUd();

 

         

猜你喜欢