我仍然不知道爲什麼從https://hc.apache.org/httpcomponents-client-ga/tutorial/html/authentication.html有關NTLM身份驗證的數獨沒有爲我工作。作爲http://www.baeldung.com/httpclient-post-http-request
描述 我終於解決了我的問題,做類似於基本身份驗證的文件,現在看起來是這樣的:
...
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,
new NTCredentials("username", "passwd", hostname, "domain.at"));
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credsProvider).build();
HttpPost post = new HttpPost("http://www.example.com"));
StringEntity input = new StringEntity(bodyAsString, HTTP.UTF_8);
input.setContentType("application/json");
input.setContentEncoding("UTF-8");
post.setEntity(input);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
HttpResponse response = client.execute(post);
...