diff --git a/Docs/说明.md b/Docs/说明.md new file mode 100644 index 0000000..a51c8d7 --- /dev/null +++ b/Docs/说明.md @@ -0,0 +1,2 @@ +HttpClientѧϰ +============== \ No newline at end of file diff --git a/HttpClientStudy.Core/HttpClientStudy.Core.csproj b/HttpClientStudy.Core/HttpClientStudy.Core.csproj index fecc597..17a26c4 100644 --- a/HttpClientStudy.Core/HttpClientStudy.Core.csproj +++ b/HttpClientStudy.Core/HttpClientStudy.Core.csproj @@ -7,6 +7,10 @@ + + + + diff --git a/HttpClientStudy.Core/PipelineClient.cs b/HttpClientStudy.Core/PipelineHttpClient.cs similarity index 95% rename from HttpClientStudy.Core/PipelineClient.cs rename to HttpClientStudy.Core/PipelineHttpClient.cs index 007ff05..668345e 100644 --- a/HttpClientStudy.Core/PipelineClient.cs +++ b/HttpClientStudy.Core/PipelineHttpClient.cs @@ -10,11 +10,11 @@ namespace HttpClientStudy.Core /// /// 管道方式 HttpClient客户端 /// - public class PipelineClient + public class PipelineHttpClient { public List HttpMessageHandlers { get; set; } - public PipelineClient() + public PipelineHttpClient() { HttpMessageHandlers = new List() { @@ -24,7 +24,7 @@ namespace HttpClientStudy.Core } - public PipelineClient(List httpMessageHandlers) + public PipelineHttpClient(List httpMessageHandlers) { HttpMessageHandlers = httpMessageHandlers; if (httpMessageHandlers == null || httpMessageHandlers?.Count == 0) diff --git a/HttpClientStudy.Core/PollyHttpClient.cs b/HttpClientStudy.Core/PollyHttpClient.cs new file mode 100644 index 0000000..2e62768 --- /dev/null +++ b/HttpClientStudy.Core/PollyHttpClient.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Polly; +using Polly.Utilities; + +namespace HttpClientStudy.Core +{ + /// + /// 使用Polly的 HttpClient + /// + public class PollyHttpClient + { + + } +} diff --git a/HttpClientStudy.Core/UsedFactoryHttpClient.cs b/HttpClientStudy.Core/UsedFactoryHttpClient.cs new file mode 100644 index 0000000..3979ed8 --- /dev/null +++ b/HttpClientStudy.Core/UsedFactoryHttpClient.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HttpClientStudy.Core +{ + /// + /// 使用工厂模式的客户端 + /// 缺点:使用IoC框架 + /// + public class UsedFactoryHttpClient + { + + } +} diff --git a/HttpClientStudy.UnitTest/PipelineClientTest.cs b/HttpClientStudy.UnitTest/PipelineClientTest.cs index 8564224..cfc923b 100644 --- a/HttpClientStudy.UnitTest/PipelineClientTest.cs +++ b/HttpClientStudy.UnitTest/PipelineClientTest.cs @@ -13,7 +13,7 @@ namespace HttpClientStudy.UnitTest [Fact] public async Task Test() { - HttpClient client = new PipelineClient().CreateHttpClient(); + HttpClient client = new PipelineHttpClient().CreateHttpClient(); var r = await client.GetAsync("https://www.baidu.com"); r.EnsureSuccessStatusCode(); diff --git a/HttpClientStudy.sln b/HttpClientStudy.sln index 40c3f2c..d592048 100644 --- a/HttpClientStudy.sln +++ b/HttpClientStudy.sln @@ -11,7 +11,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientStudy.WebApp", "H EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientStudy.UnitTest", "HttpClientStudy.UnitTest\HttpClientStudy.UnitTest.csproj", "{A64DAAE3-9FDA-4B37-AE87-FA0812DBF5A9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpClientStudy.Service", "HttpClientStudy.Service\HttpClientStudy.Service.csproj", "{5FB70481-4D39-4C90-9DAC-9453BBABD860}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HttpClientStudy.Service", "HttpClientStudy.Service\HttpClientStudy.Service.csproj", "{5FB70481-4D39-4C90-9DAC-9453BBABD860}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{56D9132E-6D9B-4D4B-B82C-D8F74AA4373A}" + ProjectSection(SolutionItems) = preProject + Docs\说明.md = Docs\说明.md + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution