for (String cookie: cookies.keySet()) {
client.getCookieManager().addCookie(new Cookie(domain, cookie, cookies.get(cookie)));
}
client.getCookieManager().setCookiesEnabled(applyCookies);
client.getOptions().setRedirectEnabled(followRedirects);
WebRequest request = new WebRequest(requestUrl(), method);
request.setRequestParameters(requestParameters());
if (body != null) request.setRequestBody(body);
if (encodingType != null) request.setEncodingType(FormEncodingType.getInstance(encodingType));
request.setAdditionalHeaders(headers);
// Clear HtmlUnit internal cache to make sure requests are actually sent
client.getCache().clear();
return new HttpResponse(client.loadWebResponse(request));
}