title: java- require basic examples showing use of new HTTP Client (v4.x)
body: <p>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)?</p>
  
  <p>(1)  set Cookie Policy</p>
  
  <p>(2) set Http Proxy- defining host/domain as well as username/password</p>
  
  <p>Currently this is done in the following manner-- </p>
  
  <pre><code>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);
  </code></pre>
  
  <p>(3)  Auth credentials are defined in the old http client with the following code--</p>
  
  <pre><code>  client.getState().setCredentials(
                  new AuthScope(urlObj.getHost(), urlObj.getPort()),
                  new UsernamePasswordCredentials(username, password)
              );
  </code></pre>
  
  <p>What is the way to do this in the new HTTP client?</p>
  
  <p>(4) Declaring a new HTTP Method variable and for this variable, Specifying method- as GET or POST</p>
  
  <p>Code used for the above currently--</p>
  
  <pre><code> HttpMethodBase method;
  method = createPostMethod(url, params, multipart, charset);
   method = createGetMethod(url, params, charset);
  </code></pre>
  
  <p>(5) Adding request headers to a method - </p>
  
  <p>For example, to set the user agent as Default user agent, the following code is used--</p>
  
  <pre><code>method.addRequestHeader(new Header("User-Agent", DEFAULT_USER_AGENT));
  </code></pre>