【问题标题】:Ntlm code works on only Samsung devicesNtlm 代码仅适用于三星设备
【发布时间】:2014-05-26 11:49:40
【问题描述】:

我在这个 url 使用 NTLM 验证码; http://hc.apache.org/httpcomponents-client-4.3.x/ntlm.html

但它仅在三星设备上进行身份验证。当我尝试使用 Nexus 4 时,我从服务器收到“由于凭据无效而拒绝访问”错误消息。即使在相同的 Android 版本中。

这可能吗?

我得到这样的 httpclient 对象;

Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create()
            .register(AuthSchemes.NTLM, new JCIFSNTLMSchemeFactory())
            .register(AuthSchemes.BASIC, new BasicSchemeFactoryHC4())
            .register(AuthSchemes.DIGEST, new DigestSchemeFactoryHC4())
            .build();

CredentialsProvider cp = new BasicCredentialsProvider();
cp.setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new NTCredentials(NTLM_USERNAME, NTLM_PASSWORD, "", ""));
CloseableHttpClient httpClient = HttpClients.custom()
            .setDefaultAuthSchemeRegistry(authSchemeRegistry)
            .setDefaultCredentialsProvider(cp)
            .build();

【问题讨论】:

  • 分享部分源代码,例如“httpClient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());"等

标签: android httpclient ntlm


【解决方案1】:

我真的不知道你为什么会有这个错误,但是如果你只需要 NTML 身份验证,你可以尝试使用我的代码。


public class JsonRpcClient {

    private static final String HOST = "blabla.yourhostname.com";

    private final AbstractHttpClient httpClient;

    public JsonRpcClient(String username, String password) {
        httpClient = new DefaultHttpClient();
        httpClient.getAuthSchemes().register("ntlm", new JCIFSNTLMSchemeFactory());
        httpClient.getCredentialsProvider().setCredentials(
            new AuthScope(HOST, -1),
            new NTCredentials(username, password, "", ""));
    }

    ...

}

它适用于我在 nexus 4 和模拟器上。

【讨论】:

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