Jho*_*hon 5 java apache apache-httpclient-4.x
我有4个互联网IP的机器,我想知道我是否可以使apache http客户端从特定的IP /网络接口发出请求
使用HttpClient 4.3 API
RequestConfig config = RequestConfig.custom()
.setLocalAddress(InetAddress.getByAddress(new byte[] {127,0,0,1}))
.build();
HttpGet httpGet = new HttpGet("/stuff");
httpGet.setConfig(config);
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
CloseableHttpResponse response = httpClient.execute(httpGet);
try {
// do something useful
} finally {
response.close();
}
} finally {
httpClient.close();
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3005 次 |
最近记录: |