Android Authentication scheme ntlm not supported

前端 未结 4 2050
别那么骄傲
别那么骄傲 2021-02-10 16:31

I am using asynhttpClient for basic authentication

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

that is looj lib..

below is my code:

usernameRandomPassw

4条回答
  •  醉酒成梦
    2021-02-10 16:44

    here is the full fledged working for this.

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

    please note to include these imports only

    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;
    

    and do use httpclient-android-4.3.5.1.jar only.

提交回复
热议问题