CloseableHttpClient httpClient = HttpClients.createDefault();
//把代理设置到请求配置 代理IP 端口 192.2120.222.226
HttpHost proxy = new HttpHost("192.2120.222.226", 80);
//超时时间单位为毫秒
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setConnectTimeout(2000).setSocketTimeout(2000)
.setProxy(proxy).build();
httpClient = HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build();
HttpResponse res = httpClient.execute(post);
//设置URLConnection 的代理
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
URLConnection conn = url.openConnection(proxy);