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

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

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

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

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

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

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

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

                    return(result);
                }
            }
        }