mirror of
https://github.com/KevinWG/OSS.Tools.git
synced 2026-10-20 15:53:01 +08:00
修改timeout处理,优化请求方法
This commit is contained in:
@@ -9,10 +9,10 @@
|
||||
<Copyright>OSSCoder</Copyright>
|
||||
<PackageProjectUrl>https://github.com/KevinWG/OSS.Http</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/KevinWG/OSS.Http</RepositoryUrl>
|
||||
<Version>1.3.2</Version>
|
||||
<PackageReleaseNotes>优化返回结果</PackageReleaseNotes>
|
||||
<AssemblyVersion>1.3.2.0</AssemblyVersion>
|
||||
<FileVersion>1.3.2.0</FileVersion>
|
||||
<Version>1.3.2.1</Version>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<AssemblyVersion>1.3.2.1</AssemblyVersion>
|
||||
<FileVersion>1.3.2.1</FileVersion>
|
||||
<PackageIconUrl>http://img1.static.osscoder.com/logo.jpg</PackageIconUrl>
|
||||
<PackageLicenseUrl>https://github.com/KevinWG/OSS.Http/blob/master/LICENSE</PackageLicenseUrl>
|
||||
</PropertyGroup>
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="OSS.Common" Version="1.3.5.16" />
|
||||
<PackageReference Include="OSS.Common" Version="1.3.6" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -30,11 +30,42 @@ namespace OSS.Http.Extention
|
||||
/// 编码格式
|
||||
/// </summary>
|
||||
public static Encoding Encoding { get; set; } = Encoding.UTF8;
|
||||
|
||||
//private static readonly Dictionary<string,Action<HttpContentHeaders,string>> _notCanAddContentHeaderDics
|
||||
// =new Dictionary<string, Action<HttpContentHeaders, string>>();
|
||||
|
||||
#region 扩展方法
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 发送Post请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="client"></param>
|
||||
/// <returns>自定义的Response结果</returns>
|
||||
public static Task<HttpResponseMessage> PostAsync(this HttpClient client, OsHttpRequest request)
|
||||
{
|
||||
request.HttpMethod = HttpMethod.Post;
|
||||
|
||||
return RestSend(client, request);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送Get请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="client"></param>
|
||||
/// <returns>自定义的Response结果</returns>
|
||||
public static Task<HttpResponseMessage> GetAsync(this HttpClient client, OsHttpRequest request)
|
||||
{
|
||||
request.HttpMethod = HttpMethod.Get;
|
||||
|
||||
return RestSend(client,request);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 执行请求方法
|
||||
/// </summary>
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -25,11 +25,37 @@ namespace OSS.Http.Extention
|
||||
/// </summary>
|
||||
public static class RestExtention
|
||||
{
|
||||
|
||||
|
||||
#region 扩展方法
|
||||
|
||||
/// <summary>
|
||||
/// 同步的请求方式
|
||||
/// 发送Post请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="client"></param>
|
||||
/// <returns>自定义的Response结果</returns>
|
||||
public static Task<HttpResponseMessage> PostAsync(this OsHttpRequest request, HttpClient client = null)
|
||||
{
|
||||
request.HttpMethod = HttpMethod.Post;
|
||||
|
||||
return RestSend(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None, client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送Get请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="client"></param>
|
||||
/// <returns>自定义的Response结果</returns>
|
||||
public static Task<HttpResponseMessage> GetAsync(this OsHttpRequest request, HttpClient client = null)
|
||||
{
|
||||
request.HttpMethod=HttpMethod.Get;
|
||||
|
||||
return RestSend(request, HttpCompletionOption.ResponseContentRead, CancellationToken.None, client);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="client"></param>
|
||||
@@ -40,7 +66,7 @@ namespace OSS.Http.Extention
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步的请求方式
|
||||
/// 发送请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="completionOption"></param>
|
||||
@@ -53,7 +79,7 @@ namespace OSS.Http.Extention
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步的请求方式
|
||||
/// 发送请求
|
||||
/// </summary>
|
||||
/// <param name="request">请求的参数</param>
|
||||
/// <param name="completionOption"></param>
|
||||
|
||||
@@ -21,7 +21,13 @@ namespace OSS.Http.Mos
|
||||
/// </summary>
|
||||
public class OsHttpRequest
|
||||
{
|
||||
|
||||
public OsHttpRequest()
|
||||
{
|
||||
}
|
||||
|
||||
public OsHttpRequest(string reqUrl)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求地址信息
|
||||
@@ -113,10 +119,10 @@ namespace OSS.Http.Mos
|
||||
/// </summary>
|
||||
public string CustomBody { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 超时时间(毫秒)
|
||||
/// </summary>
|
||||
public int TimeOutMilSeconds { get; set; }
|
||||
///// <summary>
|
||||
///// 超时时间(毫秒)
|
||||
///// </summary>
|
||||
//public int TimeOutMilSeconds { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<Version>2.5.0.1</Version>
|
||||
<Version>2.5.1.0</Version>
|
||||
<Authors>Kevin</Authors>
|
||||
<Company>OSSCoder</Company>
|
||||
<Product>OSS系列</Product>
|
||||
@@ -10,10 +10,10 @@
|
||||
<PackageProjectUrl>https://github.com/KevinWG/OSS.Http</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/KevinWG/OSS.Http</RepositoryUrl>
|
||||
<PackageIconUrl>http://img1.static.osscoder.com/logo.jpg</PackageIconUrl>
|
||||
<AssemblyVersion>2.5.0.1</AssemblyVersion>
|
||||
<FileVersion>2.5.0.1</FileVersion>
|
||||
<PackageReleaseNotes>1. 默认代理关闭
|
||||
2. 空值时过滤处理</PackageReleaseNotes>
|
||||
<AssemblyVersion>2.5.1.0</AssemblyVersion>
|
||||
<FileVersion>2.5.1.0</FileVersion>
|
||||
<PackageReleaseNotes>1. 添加get,post扩展
|
||||
2. 优化request类</PackageReleaseNotes>
|
||||
<PackageLicenseUrl>https://github.com/KevinWG/OSS.Http/blob/master/LICENSE</PackageLicenseUrl>
|
||||
<Copyright>OSSCoder</Copyright>
|
||||
</PropertyGroup>
|
||||
|
||||
Reference in New Issue
Block a user