How can I make WebClient download external css stylesheets and image bodies just like a usual web browser does?
Here's what I came up with:
public InputStream httpGetLowLevel(URL url) throws IOException
{
WebRequest wrq=new WebRequest(url);
ProxyConfig config =webClient.getProxyConfig();
//set request webproxy
wrq.setProxyHost(config.getProxyHost());
wrq.setProxyPort(config.getProxyPort());
wrq.setCredentials(webClient.getCredentialsProvider().getCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort())));
for(Cookie c:webClient.getCookieManager().getCookies(url)){
wrq.setAdditionalHeader("Cookie", c.toString());
}
WebResponse wr= webClient.getWebConnection().getResponse(wrq);
return wr.getContentAsStream();
}
My tests show, that it does support proxys and that it not only carries cookies from WebClient, but also if server sends new cookies during the response, the WebClient will eat those cookies