NTLM認証を行うコード(Java)

[English]

JavaでNTML認証を行うサンプル

// HttpClientのバージョンは 4.3.3
String userName = "test";
String password = "test";
HttpClientBuilder builder = HttpClientBuilder.create();
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new NTCredentials(userName + ":" + password));
builder.setDefaultCredentialsProvider(credentialsProvider);
 
HttpClient httpClient = builder.build();
HttpGet httpGet = new HttpGet("http://hogehoge");
 
try {
    HttpResponse response = httpClient.execute(httpGet);
    response.getEntity().writeTo(System.out);
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}