コード例 #1
0
 private void SetupCredentials()
 {
     if (!string.IsNullOrEmpty(ApiKey))
     {
         httpClient.AddApiKeyIfSet(ApiKey);
     }
     else
     {
         httpClient.AddAuthenticationHeaderIfSet(AuthenticationHeaderValue);
     }
 }
コード例 #2
0
        public async Task <T> Get <T>(Uri uri, MimeType mimeType) where T : class, new()
        {
            httpClient.AddApiKeyIfSet(ApiKey);
            httpClient.AddImpersonationHeaderIfSet(ImpersonateUser);
            httpClient.AddContentType($"{APPLICATION}/{UrlBuilder.mimeTypes[mimeType]}");

            using (var responseMessage = await httpClient.GetAsync(uri).ConfigureAwait(false))
            {
                var tc = await responseMessage.CreateTaskCompletionSource <T>(mimeType).ConfigureAwait(false);

                return(await tc.Task);
            }
        }