Ejemplo n.º 1
0
        /// <summary>
        /// 异步发送请求
        /// </summary>
        /// <param name="request">请求消息</param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> SendAsync(HttpApiRequestMessage request)
        {
            try
            {
                Interlocked.Increment(ref this.pendingCount);

                var timeout           = request.Timeout.HasValue ? request.Timeout.Value : this.Timeout;
                var cancellationToken = new CancellationTokenSource(timeout).Token;
                return(await this.client.SendAsync(request, cancellationToken));
            }
            finally
            {
                Interlocked.Decrement(ref this.pendingCount);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 异步发送请求
        /// </summary>
        /// <param name="request">请求消息</param>
        /// <returns></returns>
        public async Task <HttpResponseMessage> SendAsync(HttpApiRequestMessage request)
        {
            if (request.RequestUri == null)
            {
                throw new ApiConfigException("未配置RequestUri,RequestUri不能为null");
            }

            try
            {
                Interlocked.Increment(ref this.pendingCount);

                var timeout           = request.Timeout.HasValue ? request.Timeout.Value : this.Timeout;
                var cancellationToken = new CancellationTokenSource(timeout).Token;
                return(await this.client.SendAsync(request, cancellationToken));
            }
            finally
            {
                Interlocked.Decrement(ref this.pendingCount);
            }
        }