Android应用中的NTLM身份验证

时间:2012-04-20 21:54:40

标签: android authentication ntlm

我正在使用JCIFS库找到here在我的Android应用程序中使用NTLM身份验证。当它刚刚访问某个站点并解析了一个xml时,该应用程序工作正常,但现在我添加了NTLM auth它没有似乎工作。任何人都可以从这段代码中看出httpclient和输入流之间的问题是什么?

DefaultHttpClient client = new DefaultHttpClient();
client.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
client.getCredentialsProvider().setCredentials(new AuthScope("http://www.musowls.org",80),
new NTCredentials(username, password, null, "musschool"));  
HttpGet request = new HttpGet("http://www.musowls.org/assignments/assignmentsbystudentxml.aspx");
 HttpResponse resp = client.execute(request);
 HttpEntity entity = resp.getEntity();
 InputStream inputStream = entity.getContent();

3 个答案:

答案 0 :(得分:0)

尝试以下代码,它可能对您有帮助。

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());

NTCredentials creds = new NTCredentials("user_name", "password", "", "http://www.musowls.org/");

httpclient.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
HttpConnectionParams.setConnectionTimeout(httpclient.getParams(), 5000);

HttpPost httppost = new HttpPost("http://www.musowls.org/assignments/assignmentsbystudentxml.aspx");
httppost.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
HttpResponse response = httpclient.execute(httppost); // ERROR HAPPENS HERE

responseXML = EntityUtils.toString(response.getEntity());
Log.d("Responce", responseXML);

答案 1 :(得分:0)

1)从这里下载JCIFS:http://jcifs.samba.org/

2)按照此处的说明操作:http://hc.apache.org/httpcomponents-client-ga/ntlm.html

答案 2 :(得分:0)

长期坚持这个问题。

查看此主题中的答案,使用OkHttp3进行NTLM身份验证调用:

https://stackoverflow.com/a/42114591/3708094