我有 4 个互联网 IP 的机器,我想知道我是否可以让 apache http 客户端从特定的 ip/网络接口发出请求
问问题
3336 次
2 回答
6
使用 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();
}
于 2013-09-07T16:30:50.923 回答
0
从来没有这样做过,但是 API 中有一个ClientConnectionOperator接口(以及一些工厂)来创建套接字。也许您可以实现自己的并使用具体接口创建套接字。
于 2013-09-07T15:45:38.907 回答