【问题标题】:NTLM authentication in Android appAndroid 应用中的 NTLM 身份验证
【发布时间】:2012-04-20 21:54:39
【问题描述】:

我正在使用找到 here 的 JCIFS 库在我的 android 应用程序中使用 NTLM 身份验证。该应用程序在访问站点并解析 xml 时运行良好,但现在我添加了 NTLM 身份验证它没有似乎正在工作。任何人都可以从这段代码的 sn-p 中看出问题出在 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();

【问题讨论】:

    标签: android authentication ntlm


    【解决方案1】:

    试试下面的代码可能对你有帮助。

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

        【解决方案3】:

        被这个问题困扰太久了。

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

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多