Sample code for NTML Authentication(Java)

[japanese(日本語)]

NTML Authentication sample code for Java

// HttpClient Version is 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();
}