屏蔽WebApi中 请求资源不支持 http 方法"GET"的提示信息

        protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            return base.SendAsync(request, cancellationToken).ContinueWith(responseTask =>
            {
                HttpResponseMessage response = null;
                Task.Run(async () =>
                {
                    response = await responseTask;
                })
                .GetAwaiter()
                .GetResult();
                HttpError error;
                response.TryGetContentValue(out error);

                if (error != null)
                {
                    throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
                }
                else
                {
                    return response;
                }
            });
        }

 

posted @ 2017-12-28 10:50  Varorbc  阅读(4331)  评论(0编辑  收藏  举报