Ejemplo n.º 1
0
 /// <summary>
 /// Создать api клиент c jwt токеном
 /// </summary>
 public static IRestHttpClient GetRestClient(IHostConfigurationDomain hostConfiguration, string jwtToken) =>
 new HttpClientHandler().
 VoidOk(handler => hostConfiguration.DisableSSL,
        handler => handler.ClientCertificateOptions = ClientCertificateOption.Manual).
 VoidOk(handler => hostConfiguration.DisableSSL,
        handler => handler.ServerCertificateCustomValidationCallback =
            (httpRequestMessage, cert, cetChain, policyErrors) => true).
 Map(handler => new HttpClient(handler)
 {
     BaseAddress = hostConfiguration.Host,
     Timeout     = hostConfiguration.TimeOut,
 }).
 VoidOk(_ => !String.IsNullOrWhiteSpace(jwtToken),
        httpClient => httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(JWT_SCHEME, jwtToken)).
 Map(httpClient => new RestHttpClient(httpClient));
Ejemplo n.º 2
0
 /// <summary>
 /// Создать api клиент
 /// </summary>
 public static IRestHttpClient GetRestClient(IHostConfigurationDomain hostConfiguration) =>
 GetRestClient(hostConfiguration, String.Empty);