3

我正在使用此处找到的 JCIFS 库我的 android 应用程序中使用 NTLM 身份验证。该应用程序在访问站点并解析 xml 时运行良好,但现在我添加了 NTLM 身份验证,它似乎无法正常工作。任何人都可以从这段代码中判断出问题出在 httpclient 和 inputstream 之间吗?

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();
4

3 回答 3

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);
于 2014-04-15T13:07:36.230 回答
0

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

2)按照这里的说明:http: //hc.apache.org/httpcomponents-client-ga/ntlm.html

于 2015-03-10T00:19:26.230 回答
0

卡在这个问题上太久了。

查看此线程中的答案以使用 OkHttp3 进行 NTLM Authenticated 调用:

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

于 2017-03-02T20:31:15.920 回答