public async Task <StreamBody> PostStreamAsync(string url, FormData formData, int retry_count = 0)
        {
            try
            {
                this.AddDispose(formData);
                using (var content = formData?.GetContent())
                {
                    using (var request = new HttpRequestMessage(HttpMethod.Post, this.BuildUrl(url)))
                    {
                        this.SetDefault(request);
                        request.Content = content;
                        var t = await this.m_client.SendAsync(request);

                        StreamBody result = new StreamBody(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.PostStreamAsync(url, formData, retry_count));
                    }
                }

                throw ex;
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="url"></param>
        /// <param name="retry_count">io异常重试次数,-1.不重试,0.重试三次</param>
        /// <returns></returns>
        public async Task <StreamBody> DeleteStreamAsync(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);

                    StreamBody result = new StreamBody(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.DeleteStreamAsync(url, retry_count));
                    }
                }

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

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

                return(result);
            }
        }
Exemple #4
0
        public async Task <StreamBody> PutStreamAsync(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);

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

                    return(result);
                }
            }
        }