HttpClientBuilder中設定代理伺服器 - TCoolsIT

banq發表於2020-04-03

使用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();


 

相關文章