不支持Android身份验证方案ntlm

mor*_*rya 4 android

我使用asynhttpClient进行基本身份验证

http://loopj.com/android-async-http/

这是looj lib ..

下面是我的代码:

usernameRandomPassword = userName +":"+密码;

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

        }
Run Code Online (Sandbox Code Playgroud)

但我总是在控制台401中收到,下面是日志

验证方案ntlm不受支持.
无法应对任何这些挑战:{ntlm = WWW-Authenticate:NTLM,negotiate = WWW-Authenticate:Negotiate}

我在直接链接上检查了凭据是否正确.

我已经花了一整天的时间,任何人都可以帮助我吗?如果你分享一些例子,那将非常有帮助.

提前致谢..

mor*_*rya 10

这是通过代码的答案:

将以下代码添加到您的Android文件中

            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);
Run Code Online (Sandbox Code Playgroud)

现在从中下载lib和java文件

https://github.com/masconsult/android-ntlm

并将jcifs-1.3.17.jar复制到您的lib文件夹,将JCIFSEngine和NTLMSchemeFactory复制到您的包中.(如果你愿意,你可以改变包裹..)

多数民众赞成你的应用程序已准备好运行.

更有用的链接:

http://www.developergarden.com/en/marketplace/components/details/cmp/android-ntlm-authentication/