不支持Android的认证方案NTLM [英] Android Authentication scheme ntlm not supported
问题描述
我使用asynhttpClient基本身份验证
I am using asynhttpClient for basic authentication
http://loopj.com/android-async-http/
这是looj lib中。
that is looj lib..
下面是我的code:
usernameRandomPassword =用户名+:+密码;
usernameRandomPassword = userName + ":" + password;
Log.d("username=",usernameRandomPassword);
Log.d("url=",url);
String authorization = "Basic " + Base64.encodeToString(usernameRandomPassword.getBytes("UTF-8"), Base64.NO_WRAP);
httpClient.addHeader("Authorization",authorization);
httpClient.addHeader("Content-type", "application/json");
httpClient.setTimeout(20000);
httpClient.get( url, new AsyncHttpResponseHandler() {
@Override
public void onStart() {
System.out.println("on satrt");
super.onStart();
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
System.out.println("on onSuccess statusCode="+statusCode);
toastmessgae("onSuccess status code="+statusCode);
super.onSuccess(statusCode, headers, responseBody);
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
System.out.println("on onFailure="+statusCode);
toastmessgae("onFailure status code="+statusCode);
super.onFailure(statusCode, headers, responseBody, error);
}
@Override
public void onFinish() {
System.out.println("on onFinish");
super.onFinish();
}
});
} catch (UnsupportedEncodingException e) {
}
但我总是收到控制台401,下面是日志
but i always receive in console 401, below are logs
不支持的身份验证方案NTLM。
无法回应任何这些挑战:{= NTLM WWW身份验证:NTLM,协商= WWW身份验证:协商}
Authentication scheme ntlm not supported.
Unable to respond to any of these challenges: {ntlm=WWW-Authenticate: NTLM, negotiate=WWW-Authenticate: Negotiate}
的凭据是正确的我查了直接的联系。
The credentials are correct i checked on direct link.
我花已经在这一个完整的一天,任何一个可以帮助我吗? 如果你分享一些例子,这将是非常有帮助的。
I have spent already a complete day on this, can any one help me? If you share some example,it will be really helpful.
在此先感谢。
推荐答案
在这里是通过code答案:
here is the answer through code:
低于code添加到您的Android文件
add below code to your android file
DefaultHttpClient httpclient = new DefaultHttpClient();
// register ntlm auth scheme
httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());
httpclient.getCredentialsProvider().setCredentials(
// Limit the credentials only to the specified domain and port
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
// Specify credentials, most of the time only user/pass is needed
new NTCredentials(username, password, "", "")
);
HttpUriRequest httpget = new HttpGet(your_URL);
HttpResponse response = httpclient.execute(httpget);
String responseBody = EntityUtils.toString(response.getEntity());
Log.i(tag,"responseBody =>>>>>>>>>>"+responseBody);
现在从
https://github.com/masconsult/android-ntlm
和复制JCIFS-1.3.17.jar到您lib文件夹和 JCIFSEngine和NTLMSchemeFactory你的包。 (如果你愿意,你可以更改套餐。)
and copy jcifs-1.3.17.jar to your lib folder and JCIFSEngine and NTLMSchemeFactory to your package. (you can change package if you want..)
完蛋了您的应用程序就可以运行。
Thats it your app is ready to run.
更多有用的链接:
<一个href="http://www.developergarden.com/en/marketplace/components/details/cmp/android-ntlm-authentication/">http://www.developergarden.com/en/marketplace/components/details/cmp/android-ntlm-authentication/
这篇关于不支持Android的认证方案NTLM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!