Android ntlm authentication system not supported

I am using asynhttpClient for basic authentication

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

i.e. looj lib ..

below is my code:

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

        }

but I always get in console 401, below are the logs

The ntlm authentication scheme is not supported.
Unable to answer any of these problems: {ntlm = WWW-Authenticate: NTLM, negotiate = WWW-Authenticate: Negotiate}

The credentials are correct, I checked the direct link.

I have already spent the whole day on this, can someone help me? If you share some example, it will be really useful.

Thanks in advance.

+4
source share
4 answers

:

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

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/

+10

, , , ? NTLM Microsoft:

http://www.innovation.ch/personal/ronald/ntlm.html

Basic Auth, , , , - .

+1

. android asynk http, ntlm auth : 1) , jcifs-1.3.17.jar 2), https://github.com/loopj/android-async-http ( JAR) , 3), AsynkHttpClient.java

  httpClient = new DefaultHttpClient(cm, httpParams);

 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", "pass","", "")


    );

!!!!!!!

 httpClient.addRequestInterceptor(new HttpRequestInterceptor() {
            @Override
            public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
                AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
                CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
                        ClientContext.CREDS_PROVIDER);
                HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);

//                if (authState.getAuthScheme() == null) {
//                    AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
//                    Credentials creds = credsProvider.getCredentials(authScope);
//                    if (creds != null) {
//                        authState.setAuthScheme(new BasicScheme());
//                        authState.setCredentials(creds);
//                    }
//                }
            }
        }, 0);

, :)

0

.

try
  {
     DefaultHttpClient httpclient = new DefaultHttpClient();

  // register ntlm auth scheme
     httpclient.getAuthSchemes().register("ntlm", new NTLMSchemeFactory());

     httpclient.getCredentialsProvider().setCredentials(
             new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
             new NTCredentials("username","password"));

             //xx = ip address yy = port
     HttpPost httpPost = new HttpPost("http://xx.xx.xx.xx:yy/");

     Log.e(TAG, "executing request" + httpPost.getRequestLine());
     HttpResponse response = httpclient.execute(httpPost);

     HttpEntity entity = response.getEntity();

     Log.e(TAG, "" + response.getStatusLine());
     if (entity != null)
     {
        Log.e(TAG, "Response content length: " + entity.getContentLength());
     }
     if (entity != null)
     {
        Log.e(TAG, "Response stream: " + getMessage(entity.getContent()));
        entity.consumeContent();
     }

  }
  catch (Exception e)
  {
     Log.e(TAG, "" + e.getMessage());
  }

,

import java.net.HttpURLConnection;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.NTCredentials;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.auth.NTLMSchemeFactory;
import org.apache.http.impl.client.DefaultHttpClient;

httpclient-android-4.3.5.1.jar.

0

All Articles