コード例 #1
0
        /// <summary>
        /// Executes a <see cref="HttpMethod.Get"/> request returning the <see cref="CloudFlareResponse{T}"/>.
        /// </summary>
        /// <typeparam name="T">The type of the <see cref="CloudFlareResponse{T}.Result"/>.</typeparam>
        public static async Task <CloudFlareResponse <T> > GetCloudFlareResponseAsync <T>(
            this HttpClient client,
            Uri uri,
            CloudFlareAuth auth,
            CancellationToken cancellationToken)
            where T : class
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (uri == null)
            {
                throw new ArgumentNullException(nameof(uri));
            }
            if (auth == null)
            {
                throw new ArgumentNullException(nameof(auth));
            }

            using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
            {
                request.AddAuth(auth);

                HttpResponseMessage response =
                    await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
                    .ConfigureAwait(false);

                using (response)
                {
                    CloudFlareResponse <T> cloudFlareResponse =
                        await response.ReadCloudFlareResponseAsync <T>(cancellationToken).ConfigureAwait(false);

                    return(cloudFlareResponse);
                }
            }
        }