English 中文(简体)
使用Apache HttpClient定义源ip地址
原标题:Define source ip address using Apache HttpClient

我正在进行一个具有以下需求的项目:

  • use source ip address A to access http service S on Remote Server XX.YY.ZZ.WW
  • use source ip address B to access http service T on Remote Server XX.YY.ZZ.WW(same as above)

XX。YY。ZZ。WW是一个我无法控制的主机。

我的服务器在同一个以太网接口上配置了IP A和IP B。我的项目使用Apache HttpClient。如有必要,可以将其更改为其他内容。

根据我的TCP/IP知识,这很容易。只要我拥有IP,我就可以将源IP地址更改为我想要的任何地址。但毕竟,我不是直接操纵IP数据包。我不知道如何使用HttpClient来实现这一点。

最佳回答

您只需要告诉HttpClient要使用哪个网络接口。您可以使用连接属性执行此操作:

ConnRoutePNames.LOCAL_ADDRESS= ADDRESS A ;

查看docs获取完整描述。

问题回答
final DefaultHttpClient httpClient = new DefaultHttpClient();
HttpParams params = httpClient.getParams();
params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(IP_ADDRESS));




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签