I am working to change the HTTP client in an application from Commons HTTP Client v3.x to the new HTTP Client v4.x. I searched but could not find good examples for the following scenarios-- can you point me to a good tutorial/article on the new HTTP Client (something similar to the excellent Community Wiki article at SO on java.net.url)?
(1) set Cookie Policy
(2) set Http Proxy- defining host/domain as well as username/password
Currently this is done in the following manner--
Credentials credentials =
( host == null || domain == null || "".equals(host.trim()) ||
"".equals(domain.trim()) ) ?
new UsernamePasswordCredentials(username, password) :
new NTCredentials(username, password, host, domain);
client.getState().setProxyCredentials( AuthScope.ANY, credentials);
(3) Auth credentials are defined in the old http client with the following code--
client.getState().setCredentials(
new AuthScope(urlObj.getHost(), urlObj.getPort()),
new UsernamePasswordCredentials(username, password)
);
What is the way to do this in the new HTTP client?
(4) Declaring a new HTTP Method variable and for this variable, Specifying method- as GET or POST
Code used for the above currently--
HttpMethodBase method;
method = createPostMethod(url, params, multipart, charset);
method = createGetMethod(url, params, charset);
(5) Adding request headers to a method -
For example, to set the user agent as Default user agent, the following code is used--
method.addRequestHeader(new Header("User-Agent", DEFAULT_USER_AGENT));