使用Apache HttpClient定义源IP地址 [英] Define source ip address using Apache HttpClient

查看:586
本文介绍了使用Apache HttpClient定义源IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个有以下需求的项目:

I'm working on a project that have the following need:


  • 使用源IP地址A访问远程http服务S服务器XX.YY.ZZ.WW

  • 使用源IP地址B访问远程服务器XX.YY.ZZ.WW上的http服务T(与上面相同)

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

XX.YY.ZZ.WW is a host I have no control of.

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

My server is configured with both IP A and IP B on the same Ethernet Interface. My project uses Apache HttpClient. It can be changed to something else if necessary.

根据我的TCP / IP知识,这非常简单。只要我拥有IP,我应该能够将源IP地址更改为我想要的任何内容。但毕竟,我不是直接操纵IP数据包。我不知道如何使用HttpClient完成此操作。

Based on my TCP/IP knowledge, this is very easy. As long as I own the IP, I should be able to change the source IP address to whatever I want. But after all, I'm not manipulating IP packet directly. And I have no idea how this can be done with HttpClient.

推荐答案

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

You just need to tell HttpClient which network interface to use. You can do this with a connection property:

ConnRoutePNames.LOCAL_ADDRESS='ADDRESS A';

查看 docs 以获取完整描述。

这篇关于使用Apache HttpClient定义源IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆