From 3655c0877c772e64d41ca877dfd2edeed37b1e62 Mon Sep 17 00:00:00 2001 From: KevinWG <1985088337@qq.com> Date: Sat, 13 Jul 2019 11:12:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9timeout=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E8=AF=B7=E6=B1=82=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OSS.Http.Extention/OSS.Http.Extention.csproj | 10 +++--- OSS.Http.Extention/OsRestExtention.cs | 1 - OSS.Http/Extention/HttpClientExtention.cs | 36 ++++++++++++++++++-- OSS.Http/Extention/RestExtention.cs | 34 +++++++++++++++--- OSS.Http/Mos/OsHttpRequest.cs | 16 ++++++--- OSS.Http/OSS.Http.csproj | 10 +++--- 6 files changed, 85 insertions(+), 22 deletions(-) diff --git a/OSS.Http.Extention/OSS.Http.Extention.csproj b/OSS.Http.Extention/OSS.Http.Extention.csproj index 9a6fcbc..a1755c9 100644 --- a/OSS.Http.Extention/OSS.Http.Extention.csproj +++ b/OSS.Http.Extention/OSS.Http.Extention.csproj @@ -9,10 +9,10 @@ OSSCoder https://github.com/KevinWG/OSS.Http https://github.com/KevinWG/OSS.Http - 1.3.2 - 优化返回结果 - 1.3.2.0 - 1.3.2.0 + 1.3.2.1 + + 1.3.2.1 + 1.3.2.1 http://img1.static.osscoder.com/logo.jpg https://github.com/KevinWG/OSS.Http/blob/master/LICENSE @@ -27,7 +27,7 @@ - + diff --git a/OSS.Http.Extention/OsRestExtention.cs b/OSS.Http.Extention/OsRestExtention.cs index 6f76797..0f276e1 100644 --- a/OSS.Http.Extention/OsRestExtention.cs +++ b/OSS.Http.Extention/OsRestExtention.cs @@ -16,7 +16,6 @@ using System.Net.Http; using System.Threading.Tasks; using Newtonsoft.Json; using OSS.Common.ComModels; -using OSS.Common.ComModels.Enums; using OSS.Common.Plugs; using OSS.Http.Mos; diff --git a/OSS.Http/Extention/HttpClientExtention.cs b/OSS.Http/Extention/HttpClientExtention.cs index 5a7c666..20f80a4 100644 --- a/OSS.Http/Extention/HttpClientExtention.cs +++ b/OSS.Http/Extention/HttpClientExtention.cs @@ -30,11 +30,42 @@ namespace OSS.Http.Extention /// 编码格式 /// public static Encoding Encoding { get; set; } = Encoding.UTF8; + //private static readonly Dictionary> _notCanAddContentHeaderDics // =new Dictionary>(); #region 扩展方法 + + /// + /// 发送Post请求 + /// + /// 请求的参数 + /// + /// 自定义的Response结果 + public static Task PostAsync(this HttpClient client, OsHttpRequest request) + { + request.HttpMethod = HttpMethod.Post; + + return RestSend(client, request); + } + + /// + /// 发送Get请求 + /// + /// 请求的参数 + /// + /// 自定义的Response结果 + public static Task GetAsync(this HttpClient client, OsHttpRequest request) + { + request.HttpMethod = HttpMethod.Get; + + return RestSend(client,request); + } + + + + /// /// 执行请求方法 /// @@ -73,8 +104,9 @@ namespace OSS.Http.Extention { var reqMsg = ConfigureReqMsg(request); - if (request.TimeOutMilSeconds > 0) - client.Timeout = TimeSpan.FromMilliseconds(request.TimeOutMilSeconds); + + //if (request.TimeOutMilSeconds > 0) + // client.Timeout = TimeSpan.FromMilliseconds(request.TimeOutMilSeconds); return client.SendAsync(reqMsg, completionOption, cancellationToken); } diff --git a/OSS.Http/Extention/RestExtention.cs b/OSS.Http/Extention/RestExtention.cs index 8e4f9eb..6019380 100644 --- a/OSS.Http/Extention/RestExtention.cs +++ b/OSS.Http/Extention/RestExtention.cs @@ -25,11 +25,37 @@ namespace OSS.Http.Extention /// public static class RestExtention { - + #region 扩展方法 /// - /// 同步的请求方式 + /// 发送Post请求 + /// + /// 请求的参数 + /// + /// 自定义的Response结果 + public static Task PostAsync(this OsHttpRequest request, HttpClient client = null) + { + request.HttpMethod = HttpMethod.Post; + + return RestSend(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None, client); + } + + /// + /// 发送Get请求 + /// + /// 请求的参数 + /// + /// 自定义的Response结果 + public static Task GetAsync(this OsHttpRequest request, HttpClient client = null) + { + request.HttpMethod=HttpMethod.Get; + + return RestSend(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None, client); + } + + /// + /// 发送请求 /// /// 请求的参数 /// @@ -40,7 +66,7 @@ namespace OSS.Http.Extention } /// - /// 同步的请求方式 + /// 发送请求 /// /// 请求的参数 /// @@ -53,7 +79,7 @@ namespace OSS.Http.Extention } /// - /// 同步的请求方式 + /// 发送请求 /// /// 请求的参数 /// diff --git a/OSS.Http/Mos/OsHttpRequest.cs b/OSS.Http/Mos/OsHttpRequest.cs index e3185ea..3ba135b 100644 --- a/OSS.Http/Mos/OsHttpRequest.cs +++ b/OSS.Http/Mos/OsHttpRequest.cs @@ -21,7 +21,13 @@ namespace OSS.Http.Mos /// public class OsHttpRequest { - + public OsHttpRequest() + { + } + + public OsHttpRequest(string reqUrl) + { + } /// /// 请求地址信息 @@ -113,10 +119,10 @@ namespace OSS.Http.Mos /// public string CustomBody { get; set; } - /// - /// 超时时间(毫秒) - /// - public int TimeOutMilSeconds { get; set; } + ///// + ///// 超时时间(毫秒) + ///// + //public int TimeOutMilSeconds { get; set; } } } diff --git a/OSS.Http/OSS.Http.csproj b/OSS.Http/OSS.Http.csproj index d539e2a..a8640a9 100644 --- a/OSS.Http/OSS.Http.csproj +++ b/OSS.Http/OSS.Http.csproj @@ -2,7 +2,7 @@ netstandard2.0 - 2.5.0.1 + 2.5.1.0 Kevin OSSCoder OSS系列 @@ -10,10 +10,10 @@ https://github.com/KevinWG/OSS.Http https://github.com/KevinWG/OSS.Http http://img1.static.osscoder.com/logo.jpg - 2.5.0.1 - 2.5.0.1 - 1. 默认代理关闭 -2. 空值时过滤处理 + 2.5.1.0 + 2.5.1.0 + 1. 添加get,post扩展 +2. 优化request类 https://github.com/KevinWG/OSS.Http/blob/master/LICENSE OSSCoder