public RpcClient(Uri baseUrl, HttpClient httpClient, AuthenticationHeaderValue authHeaderValue = null,
                         JsonSerializerSettings jsonSerializerSettings = null, ILog log = null)
        {
            _baseUrl = baseUrl;

            if (authHeaderValue == null)
            {
                authHeaderValue = UserAuthentication.FromUri(baseUrl)?.GetBasicAuthenticationHeaderValue();
            }

            _authHeaderValue = authHeaderValue;
            if (jsonSerializerSettings == null)
            {
                jsonSerializerSettings = DefaultJsonSerializerSettingsFactory.BuildDefaultJsonSerializerSettings();
            }
            _jsonSerializerSettings = jsonSerializerSettings;
            _log = log;
            InitialiseHttpClient(httpClient);
            _httpClient        = httpClient;
            _rotateHttpClients = false;
        }
示例#2
0
        public static UserAuthentication FromUri(Uri uri)
        {
            if (string.IsNullOrEmpty(uri.UserInfo))
            {
                return(null);
            }

            var userInfo = uri.UserInfo?.Split(':');
            UserAuthentication userAuthentication = null;

            if (userInfo != null)
            {
                userAuthentication          = new UserAuthentication();
                userAuthentication.UserName = userInfo[0];
                if (userInfo.Length > 1)
                {
                    userAuthentication.Password = userInfo[1];
                }
            }

            return(userAuthentication);
        }