原文地址: http://www.asp.net/web-api/overview/web-api-clients/httpclient-message-handlers

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;

namespace Test.WebAPI.Client
{
    public class CustomClientMessageHandler : DelegatingHandler 
    {
        private int count = 0;
        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            count++;
            Console.WriteLine(count);

            var response = await base.SendAsync(request, cancellationToken);

            if (!response.IsSuccessStatusCode)
            {
                Console.WriteLine("{0}\t{1}\t{2}", request.RequestUri, (int)response.StatusCode, response.Headers.Date);
            }

            return response;
        }
    }
}
CustomClientMessageHandler.cs

相关文章:

  • 2020-02-23
  • 2018-11-21
  • 2017-12-19
  • 2017-11-26
  • 2018-06-28
  • 2018-04-03
  • 2019-12-05
  • 2018-04-06
猜你喜欢
  • 2019-06-24
  • 2018-02-07
  • 2019-08-26
  • 2019-06-18
  • 2018-11-09
  • 2019-08-24
  • 2018-11-12
  • 2019-08-25
相关资源
相似解决方案