我在这个网址上使用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();
答案 0 :(得分:0)
我真的不知道你为什么会遇到这个bug,但如果你只需要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和模拟器。