HttpURLConnection类没有找到在Android上的NTLM挑战 [英] HttpUrlConnection doesn't find the NTLM challenge on Android

查看:737
本文介绍了HttpURLConnection类没有找到在Android上的NTLM挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的Andr​​oid应用程序连接到使用的HttpURLConnection类IIS服务器。

I'm trying to connect my Android app to an IIS server using the HttpUrlConnection class.

我的服务器需要用户为进行验证,所以它发送下面挑战给客户端:

My server needs the user to be authenticate, so it is sending the following challenge to the client :

WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM

我的问题是HttpURLConnection的似乎并不解析它。所以的getPasswordAut​​hentication()永远不会调用,并返回一个IOException异常无身份验证的挑战找到了。

My problem is that HttpUrlConnection doesn't seems to parse it. So getPasswordAuthentication() is never call, and it return an IOException "no authentication challenges found".

下面是我的code:

Authenticator.setDefault(new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {                  

            return new PasswordAuthentication("myUsername", "myPassword".toCharArray());
    }               
});

URL url = new URL(myUrl);               
HttpURLConnection conn = (HttpURLConnection) url.openConnection();          

conn.setRequestMethod("GET");
conn.setRequestProperty("Accept-Encoding", "gzip");
conn.setRequestProperty("Accept-Charset", "UTF-8");         
conn.setRequestProperty("Accept", "*/*");
conn.setRequestProperty("Connection", "close");
conn.setDoOutput(true);
conn.setDoInput(true);          

try 
{   
    conn.connect();             
    status_code = conn.getResponseCode();   
}catch (IOException e) {
    ...             
}

我真的开始觉得NTLM挑战是不支持的HttpURLConnection。我看到一些图书馆似乎做的工作,但我想preFER不使用外部库。

I'm really starting to think that NTLM challenge is just not supported by HttpUrlConnection. I saw some libraries that seems to do the work, but I would prefer not to use external libraries.

有人可以确认是否是可以或不可以做的HttpURLConnection手柄NTLM挑战,而无需外部库?

Can somebody confirm if it is possible or not to make HttpUrlConnection handle NTLM challenge without external libs?

推荐答案

我只能够使通过设置AuthScheme及以下的图书馆用HttpClient的工作: http://jcifs.samba.org/src/jcifs-krb5-1.3.17.zip

I've only been able to make it work with HttpClient by setting the AuthScheme and the library below: http://jcifs.samba.org/src/jcifs-krb5-1.3.17.zip.

HttpClient httpclient = new HttpClient(httpParameters, context);
NTCredentials creds = new NTCredentials("username", "password", "", "dir");
httpclient.getCredentialsProvider().setCredentials(
              new AuthScope(context.getString("whatever is your main URL"), -1), creds);
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());

然后你实现了JCIFS发动机和工厂。您可以在 http://hc.apache.org/httpcomponents-样本客户4.2.x版/ ntlm.html

这篇关于HttpURLConnection类没有找到在Android上的NTLM挑战的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆