title: NTLM authentication java via HttpClient
body: <p>My problem is i'm trying to get into scopus using a crawler but it requires my crawler to enter the site through my school proxy server. I tried authenticating but it keep responding with <code>401</code> status.</p>
  
  <pre><code>public void testConnection() throws ClientProtocolException, IOException {
      DefaultHttpClient httpclient = new DefaultHttpClient();
      List&lt;String&gt; authpref = new ArrayList&lt;String&gt;();
      authpref.add(AuthPolicy.NTLM);
      httpclient.getParams().setParameter(AuthPNames.TARGET_AUTH_PREF, authpref);
      NTCredentials creds = new NTCredentials("username","password","ezlibproxy1.ntu.edu.sg","ntu.edu.sg");//this is correct
      httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
  
      HttpHost target = new HttpHost("ezlibproxy1.ntu.edu.sg", 443, "https");//this is correct
  
      // Make sure the same context is used to execute logically related requests
      HttpContext localContext = new BasicHttpContext();
  
      // Execute a cheap method first. This will trigger NTLM authentication
      HttpGet httpget = new HttpGet("http://www-scopus-com.ezlibproxy1.ntu.edu.sg/authid/detail.url?authorId=14831850700");
      HttpResponse response = httpclient.execute(target, httpget, localContext);
      HttpEntity entity = response.getEntity();
      System.out.println(EntityUtils.toString(entity));
  
      int statusCode = response.getStatusLine().getStatusCode();
      System.out.println("Status Code:" + statusCode);
  }
  </code></pre>
  
  <p>The status code respond is <code>401 (unauthorised)</code>.
  Any suggestion on this?</p>