如何在 HtmlUnit 中使用 inetAddress 发送请求?

How to send a request with inetAddress in HtmlUnit?

我可以像上面那样通过 InetAddress 发送一个 Http GET 请求。

HttpParams params = new BasicHttpParams();
params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, InetAddress.getByName(interfaceIp));
HttpClient httpClient = new DefaultHttpClient(params);  
HttpGet httpGet = new HttpGet(baseUrl);
response = httpClient.execute(httpGet);

但我想通过 HtmlUnit 尝试一下。有办法吗?

编辑:

我试试这个:

WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage(baseurl);
page.getTitleText();

您可以使用:

InetAddress inetAddress = InetAddress.getByName(interfaceIp);
webClient.getOptions().setLocalAddress(inetAddress);