1) Basic Verification:
1 /**2 * Take pictures from the server3 * 4 * @paramURL5 * @return6 */7 Public voidGethttpbitmap (FinalString URL) {8 NewThread (NewRunnable () {9 Public voidrun () {TenBitmap Bitmap =NULL; One Try { AHttpGet HttpPost =Newhttpget (URL); -Defaulthttpclient httpClient =Newdefaulthttpclient (); - //Basic Identity Verification theBasiccredentialsprovider bcp =NewBasiccredentialsprovider (); -String userName = "UserName"; -String password = "Password"; -Authscope Authscope =NewAuthscope (authscope.any); + bcp.setcredentials (Authscope, - New Usernamepasswordcredentials (userName, password)); + A Httpclient.setcredentialsprovider (bcp); at
Basic Authentication Ends
HttpResponse HttpResponse =Httpclient.execute (httppost); -ANDROID.UTIL.LOG.I ("", "=====>" +httpresponse.getstatusline (). Getstatuscode ()); -ANDROID.UTIL.LOG.I ("", "=====>" +httpresponse.getentity (). Getcontentlength ()); -InputStream is =httpresponse.getentity (). getcontent (); -Bitmap =Bitmapfactory.decodestream (IS); - is.close (); in}Catch(Exception e) { - e.printstacktrace (); to } + - GetResult (bitmap); the } * }). Start (); $}
1 byte [] Encodedpassword = (userName + ":" + password). getBytes (); 2 httppost.addheader ("Authorization", "Base" + base64.encodetostring (Encodedpassword, base64.no_wrap);
2) NTLM authentication:
1 //Register NTLM auth scheme2Httpclient.getauthschemes (). Register ("NTLM",Newntlmschemefactory ());3 Httpclient.getcredentialsprovider (). SetCredentials (4 //Limit the credentials only to the specified domain and port5 NewAuthscope (Authscope.any_host, authscope.any_port),6 //specify credentials, most of the time was User/pass is needed7 NewNtcredentials (userName, Password, "", "")8);
Direct replacement//basic verification to use
Use Jcifs-1.3.17.jar (available for download to HTTPS://GITHUB.COM/MASCONSULT/ANDROID-NTLM)
1 Public classNtlmschemefactoryImplementsauthschemefactory2 {3 @Override4 Publicauthscheme newinstance (httpparams params)5 {6 return NewNtlmscheme (Newjcifsengine ());7 }8}
1 Public classJcifsengineImplementsNtlmengine {2 3 Private Static Final intType_1_flags =ntlmflags.ntlmssp_negotiate_564|ntlmflags.ntlmssp_negotiate_1285|ntlmflags.ntlmssp_negotiate_ntlm26|ntlmflags.ntlmssp_negotiate_always_sign7|Ntlmflags.ntlmssp_request_target;8 9 @OverrideTen Publicstring generatetype1msg (string domain, string workstation) One throwsntlmengineexception { A FinalType1message Type1message =Newtype1message (Type_1_flags, - domain, workstation); - returnBase64.encode (Type1message.tobytearray ()); the } - - @Override - Publicstring Generatetype3msg (string username, string password, + string domain, string workstation, String challenge) - throwsntlmengineexception { + type2message type2message; A at Try { -Type2message =NewType2message (Base64.decode (Challenge)); -}Catch(FinalIOException Exception) { - Throw NewNtlmengineexception ("Error in type2 message", exception); - } - in Final intType2flags =type2message.getflags (); - Final intType3flags =Type2flags to& (0xFFFFFFFF ^ (Ntlmflags.ntlmssp_target_type_domain |ntlmflags.ntlmssp_target_type_server)); + FinalType3message Type3message =Newtype3message (Type2message, - password, domain, username, workstation, type3flags); the returnBase64.encode (Type3message.tobytearray ()); * } $}
Android and IIS server Authentication