示例#1
0
        private async Task <ApiFile> SendHttpFile(Func <HttpRequestMessage> requestFunc)
        {
            var request = requestFunc();
            HttpResponseMessage response = null;

            try
            {
                int startTime = Environment.TickCount;
                response = await httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

                int duration = Environment.TickCount - startTime;
                response.EnsureSuccessStatusCode();

                return(await ApiFile.FromMessage(response, duration));
            }
            catch (Exception ex)
            {
                response?.Dispose();
                return(new ApiFile()
                {
                    Error = new ApiError {
                        Message = GetRecursiveErrorMessage(ex)
                    }
                });
            }
        }
示例#2
0
        public new static async Task <ApiFile> FromMessage(HttpResponseMessage message)
        {
            var response = new ApiFile
            {
                Message = message,
            };

            if (message.IsSuccessStatusCode)
            {
                response.Data = await message.Content.ReadAsStreamAsync();
            }
            else
            {
                response.HandleFailedCall();
            }

            return(response);
        }
示例#3
0
        private async Task <ApiFile> SendHttpFile(Func <HttpRequestMessage> requestFunc)
        {
            try
            {
                var request  = requestFunc();
                var response = await httpClient.SendAsync(request);

                return(await ApiFile.FromMessage(response));
            }
            catch (Exception ex)
            {
                return(new ApiFile()
                {
                    Error = new ApiError {
                        Message = GetRecursiveErrorMessage(ex)
                    }
                });
            }
        }