Apache HTTP client, request from a specific network interface

I have a machine with 4 Internet IPs and I want to know if I can make an apache http client for requests from a specific ip / network interface.

+4
source share
2 answers

Using HttpClient 4.3 APIs

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(); } 
+5
source

I have never done this, but there is a ClientConnectionOperator (and some factories) interface in the API for creating a socket. Perhaps you can implement your own and create a socket with a specific interface.

0
source

Source: https://habr.com/ru/post/1501064/


All Articles