Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="formData"></param>
        /// <param name="retry_count">io异常重试次数,-1.不重试,0.重试三次</param>
        /// <returns></returns>
        public async Task <BytesBody> PutBytesAsync(string url, FormData formData, int retry_count = 0)
        {
            try
            {
                this.AddDispose(formData);
                using (var content = formData?.GetContent())
                {
                    using (var request = new HttpRequestMessage(HttpMethod.Put, this.BuildUrl(url)))
                    {
                        this.SetDefault(request);
                        request.Content = content;
                        var t = await this.m_client.SendAsync(request);

                        BytesBody result = new BytesBody(t);
                        this.AddDispose(result);
                        await result.Proc();

                        return(result);
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is HttpRequestException && ex.InnerException != null && ex.InnerException is IOException)
                {
                    if (retry_count >= 0 && retry_count < 3)
                    {
                        retry_count++;
                        return(await this.PutBytesAsync(url, formData, retry_count));
                    }
                }

                throw ex;
            }
        }
Example #2
0
        /// <summary>
        /// delete
        /// </summary>
        /// <param name="url"></param>
        /// <param name="retry_count">io异常重试次数,-1.不重试,0.重试三次</param>
        /// <returns></returns>
        public async Task <BytesBody> DeleteBytesAsync(string url, int retry_count = 0)
        {
            try
            {
                using (var request = new HttpRequestMessage(HttpMethod.Delete, this.BuildUrl(url)))
                {
                    this.SetDefault(request);
                    var t = await this.m_client.SendAsync(request);

                    BytesBody result = new BytesBody(t);
                    this.AddDispose(result);
                    await result.Proc();

                    return(result);
                }
            }
            catch (Exception ex)
            {
                if (ex is HttpRequestException && ex.InnerException != null && ex.InnerException is IOException)
                {
                    if (retry_count >= 0 && retry_count < 3)
                    {
                        retry_count++;
                        return(await this.DeleteBytesAsync(url, retry_count));
                    }
                }

                throw ex;
            }
        }
Example #3
0
        public async Task <BytesBody> DeleteBytesAsync(string url)
        {
            using (var request = new HttpRequestMessage(HttpMethod.Delete, this.BuildUrl(url)))
            {
                this.SetDefault(request);
                var t = await m_client.SendAsync(request);

                BytesBody result = new BytesBody(t);
                this.AddDispose(result);
                await result.Proc();

                return(result);
            }
        }
Example #4
0
        public async Task <BytesBody> PutBytesAsync(string url, FormData formData)
        {
            this.AddDispose(formData);
            using (var content = formData?.GetContent())
            {
                using (var request = new HttpRequestMessage(HttpMethod.Put, this.BuildUrl(url)))
                {
                    this.SetDefault(request);
                    request.Content = content;
                    var t = await m_client.SendAsync(request);

                    BytesBody result = new BytesBody(t);
                    this.AddDispose(result);
                    await result.Proc();

                    return(result);
                }
            }
        }