예제 #1
0
        protected internal virtual void PreemptivelySetAuthCredentials(HttpClient httpClient
                                                                       )
        {
            bool   isUrlBasedUserInfo = false;
            string userInfo           = url.GetUserInfo();

            if (userInfo != null)
            {
                isUrlBasedUserInfo = true;
            }
            else
            {
                if (authenticator != null)
                {
                    AuthenticatorImpl auth = (AuthenticatorImpl)authenticator;
                    userInfo = auth.AuthUserInfo();
                }
            }
            if (userInfo != null)
            {
                if (userInfo.Contains(":") && !userInfo.Trim().Equals(":"))
                {
                    string[] userInfoElements = userInfo.Split(":");
                    string   username         = isUrlBasedUserInfo ? URIUtils.Decode(userInfoElements[0]) : userInfoElements
                                                [0];
                    string password = isUrlBasedUserInfo ? URIUtils.Decode(userInfoElements[1]) : userInfoElements
                                      [1];
                    Credentials credentials = new UsernamePasswordCredentials(username, password);
                    if (httpClient is DefaultHttpClient)
                    {
                        DefaultHttpClient        dhc            = (DefaultHttpClient)httpClient;
                        MessageProcessingHandler preemptiveAuth = new _MessageProcessingHandler_286(credentials
                                                                                                    );
                        dhc.AddRequestInterceptor(preemptiveAuth, 0);
                    }
                }
                else
                {
                    Log.W(Log.TagRemoteRequest, "RemoteRequest Unable to parse user info, not setting credentials"
                          );
                }
            }
        }
 protected internal virtual void PreemptivelySetAuthCredentials(HttpClient httpClient
     )
 {
     bool isUrlBasedUserInfo = false;
     string userInfo = url.GetUserInfo();
     if (userInfo != null)
     {
         isUrlBasedUserInfo = true;
     }
     else
     {
         if (authenticator != null)
         {
             AuthenticatorImpl auth = (AuthenticatorImpl)authenticator;
             userInfo = auth.AuthUserInfo();
         }
     }
     if (userInfo != null)
     {
         if (userInfo.Contains(":") && !userInfo.Trim().Equals(":"))
         {
             string[] userInfoElements = userInfo.Split(":");
             string username = isUrlBasedUserInfo ? URIUtils.Decode(userInfoElements[0]) : userInfoElements
                 [0];
             string password = isUrlBasedUserInfo ? URIUtils.Decode(userInfoElements[1]) : userInfoElements
                 [1];
             Credentials credentials = new UsernamePasswordCredentials(username, password);
             if (httpClient is DefaultHttpClient)
             {
                 DefaultHttpClient dhc = (DefaultHttpClient)httpClient;
                 MessageProcessingHandler preemptiveAuth = new _MessageProcessingHandler_286(credentials
                     );
                 dhc.AddRequestInterceptor(preemptiveAuth, 0);
             }
         }
         else
         {
             Log.W(Log.TagRemoteRequest, "RemoteRequest Unable to parse user info, not setting credentials"
                 );
         }
     }
 }