title: how to set user name/password in httpget
body: <p>I use Apache HttpComponents to access a web service, and don' know how to set user/password in the request, here is my code:</p>
  
  <pre><code>URI url = new URI(query);
  HttpGet httpget = new HttpGet(url);
  
  DefaultHttpClient httpclient = new DefaultHttpClient();
  Credentials defaultcreds = new UsernamePasswordCredentials("test", "test");
  httpclient.getCredentialsProvider().setCredentials(new AuthScope(HOST, AuthScope.ANY_PORT), defaultcreds);
  
  HttpResponse response = httpclient.execute(httpget);
  </code></pre>
  
  <p>..</p>
  
  <p>but still it got the 401 unauthorized error. </p>
  
  <pre><code>HTTP/1.1 401 Unauthorized [Server: Apache-Coyote/1.1, Pragma: No-cache, Cache-Control: no-cache, Expires: Wed, 31 Dec 1969 16:00:00 PST, WWW-Authenticate: Basic realm="MemoryRealm", Content-Type: text/html;charset=utf-8, Content-Length: 954, Date: Wed, 04 Apr 2012 02:28:49 GMT]
  </code></pre>
  
  <p>I m not sure if its the right way to set user/password? anyone can help? thanks.</p>