Search code examples
javahttprequesthtmlunithttp-request-parameters

How to send a request with inetAddress in HtmlUnit?


I can send a Http GET request by InetAddress like above.

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);

But I want to try it via HtmlUnit. Is there a way for that?

Edit:

I try this:

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

Solution

  • You can use:

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