这里的问题是在客户端使用Apache HttpClient时使用具有NTLM身份验证的Web资源。我遇到的问题是强制客户端使用NTLM身份验证。这里是一个代码sapmle。Apache HttpClient 4.1.1 NTLM身份验证不是SPNEGO
DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getAuthSchemes().register("ntlm",new NTLMSchemeFactory());
NTCredentials creds = new NTCredentials("_myUSer_","_myPass_","_myWorkstation_","_myDomain_");
httpclient.getCredentialsProvider().setCredentials(new AuthScope("serverName",80), creds);
List<String> authpref = new ArrayList<String>();
authpref.add(AuthPolicy.NTLM);
httpclient.getParams().setParameter(AuthPNames.PROXY_AUTH_PREF, authpref);
HttpHost target = new HttpHost("serverName", 80, "http");
HttpGet httpget = new HttpGet("webResource");
HttpContext localContext = new BasicHttpContext();
HttpResponse response = httpclient.execute(target, httpget, localContext);
以下是错误从Java:
org.apache.http.client.protocol.RequestTargetAuthentication process
SEVERE: Authentication error: Invalid name provided (Mechanism level: Could not load configuration file C:\WINDOWS\krb5.ini (The system cannot find the file specified))
Web服务器响应是401
。
有关为什么auth策略未正确设置的任何想法? 我在代码中丢失了什么吗?
我发现一个问题,我的代码,这是该AuthScope应指向您的代理,而不是你的目标,这并摆脱它试图使用Kerberos而不是NTLM的错误,但我仍然从服务器获得401,正确的用户名/密码/域组合的任何想法? – Kelly 2011-04-21 16:35:50
HttpClient需要更新检查我的帖子[http://stackoverflow.com/questions/5917356/httpclient-4-1-1-returns-401-when-authenticating-with-ntlm-browsers-work-fine/20047880# 20047880] [1] [1]:http://stackoverflow.com/questions/5917356/httpclient-4-1-1-returns-401-when-authenticating-with-ntlm-browsers-work - 精细/ 20047880#20047880 – 2013-11-19 11:43:09