From 822d4b262a9d146700e6a32103fc1ed333047098 Mon Sep 17 00:00:00 2001
From: wanggaofeng <15601716045@163.com>
Date: Wed, 31 Jan 2024 17:50:57 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Docs/说明.md | 2 ++
.../HttpClientStudy.Core.csproj | 4 ++++
...ipelineClient.cs => PipelineHttpClient.cs} | 6 +++---
HttpClientStudy.Core/PollyHttpClient.cs | 19 +++++++++++++++++++
HttpClientStudy.Core/UsedFactoryHttpClient.cs | 17 +++++++++++++++++
.../PipelineClientTest.cs | 2 +-
HttpClientStudy.sln | 7 ++++++-
7 files changed, 52 insertions(+), 5 deletions(-)
create mode 100644 Docs/说明.md
rename HttpClientStudy.Core/{PipelineClient.cs => PipelineHttpClient.cs} (95%)
create mode 100644 HttpClientStudy.Core/PollyHttpClient.cs
create mode 100644 HttpClientStudy.Core/UsedFactoryHttpClient.cs
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