System.Net.Http.HttpMessageHandler.SendAsync C# (CSharp) Method

SendAsync() protected abstract method

protected abstract SendAsync ( HttpRequestMessage request, CancellationToken cancellationToken ) : Task
request HttpRequestMessage
cancellationToken System.Threading.CancellationToken
return Task
        protected internal abstract Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken);

Usage Example

コード例 #1
0
        protected internal override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            if (_preAuthenticate)
            {
                TrySetBasicAuthToken(request);
            }

            HttpResponseMessage response = await _innerHandler.SendAsync(request, cancellationToken).ConfigureAwait(false);

            if (!_preAuthenticate && response.StatusCode == HttpStatusCode.Unauthorized)
            {
                HttpHeaderValueCollection <AuthenticationHeaderValue> authenticateValues = response.Headers.WwwAuthenticate;

                foreach (AuthenticationHeaderValue h in authenticateValues)
                {
                    // We only support Basic auth, ignore others
                    if (h.Scheme == "Basic")
                    {
                        if (!TrySetBasicAuthToken(request))
                        {
                            break;
                        }

                        response.Dispose();
                        response = await _innerHandler.SendAsync(request, cancellationToken).ConfigureAwait(false);

                        break;
                    }
                }
            }

            return(response);
        }
All Usage Examples Of System.Net.Http.HttpMessageHandler::SendAsync