-
-
Notifications
You must be signed in to change notification settings - Fork 9k
升级到 Apache HttpClient 5.x 作为默认 HTTP 客户端 #3824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -114,6 +114,45 @@ | |||||||||
| - **微信开放平台**(`weixin-java-open`)主要用于第三方平台,代公众号或小程序进行开发和管理 | ||||||||||
|
|
||||||||||
|
|
||||||||||
| --------------------------------- | ||||||||||
| ### HTTP 客户端支持 | ||||||||||
|
|
||||||||||
| 本项目同时支持多种 HTTP 客户端实现,默认推荐使用 **Apache HttpClient 5.x**(最新稳定版本)。 | ||||||||||
|
|
||||||||||
| #### 支持的 HTTP 客户端类型 | ||||||||||
|
|
||||||||||
| | HTTP 客户端 | 说明 | 配置值 | 推荐程度 | | ||||||||||
| |------------|------|--------|---------| | ||||||||||
| | Apache HttpClient 5.x | Apache HttpComponents Client 5.x,最新版本 | `HttpComponents` | ⭐⭐⭐⭐⭐ 推荐 | | ||||||||||
| | Apache HttpClient 4.x | Apache HttpClient 4.x,向后兼容 | `HttpClient` | ⭐⭐⭐⭐ 兼容 | | ||||||||||
| | OkHttp | Square OkHttp 客户端 | `OkHttp` | ⭐⭐⭐ 可选 | | ||||||||||
| | Jodd-http | Jodd 轻量级 HTTP 客户端 | `JoddHttp` | ⭐⭐ 可选 | | ||||||||||
|
|
||||||||||
| #### 配置方式 | ||||||||||
|
|
||||||||||
| **Spring Boot 配置示例:** | ||||||||||
|
|
||||||||||
| ```properties | ||||||||||
| # 使用 HttpClient 5.x(推荐,MP/CP/Channel/QiDian 模块默认) | ||||||||||
| wx.mp.config-storage.http-client-type=HttpComponents | ||||||||||
|
|
||||||||||
| # 使用 HttpClient 4.x(兼容模式,MiniApp 模块默认) | ||||||||||
| wx.mp.config-storage.http-client-type=HttpClient | ||||||||||
|
|
||||||||||
| # 使用 OkHttp | ||||||||||
| wx.mp.config-storage.http-client-type=OkHttp | ||||||||||
|
|
||||||||||
| # 使用 Jodd-http | ||||||||||
| wx.mp.config-storage.http-client-type=JoddHttp | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| **注意事项:** | ||||||||||
| 1. **MiniApp 模块**目前暂不支持 HttpClient 5.x,默认使用 HttpClient 4.x | ||||||||||
| 2. **MP、CP、Channel、QiDian 模块**已支持 HttpClient 5.x,默认推荐使用 | ||||||||||
|
Comment on lines
+150
to
+151
|
||||||||||
| 1. **MiniApp 模块**目前暂不支持 HttpClient 5.x,默认使用 HttpClient 4.x | |
| 2. **MP、CP、Channel、QiDian 模块**已支持 HttpClient 5.x,默认推荐使用 | |
| 1. **MiniApp 模块**已提供 `HttpComponents`(HttpClient 5.x)类型的配置选项,但当前默认仍为 HttpClient 4.x;如需启用 HttpClient 5.x,请确保所使用的集成模块(如 `wx-java-miniapp-spring-boot-starter`、`wx-java-miniapp-solon-plugin`)版本已支持该选项 | |
| 2. **MP、CP、Channel、QiDian 模块**已完整支持 HttpClient 5.x,默认推荐使用 |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档中描述「MP、CP、Channel、QiDian 模块已支持 HttpClient 5.x」,但实际上 PR 中没有修改 CP(企业微信)单体 starter 模块的 WxCpProperties。
检查发现 wx-java-cp-spring-boot-starter 模块的 WxCpProperties 类中没有 httpClientType 字段和 HttpClientType 枚举的定义(与其他模块如 MP、QiDian 不同)。这意味着该模块可能尚未完整支持多种 HTTP 客户端类型的配置切换。
建议验证 CP 模块是否真正支持 HttpClient 5.x 配置,如果不支持,应从文档描述中移除。
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,201 @@ | ||||||||||||||||||
| # HttpClient 升级指南 | ||||||||||||||||||
|
|
||||||||||||||||||
| ## 概述 | ||||||||||||||||||
|
|
||||||||||||||||||
| 从 WxJava 4.7.9.B 版本开始,项目开始支持并推荐使用 **Apache HttpClient 5.x**(HttpComponents Client 5),同时保持对 HttpClient 4.x 的向后兼容。 | ||||||||||||||||||
|
|
||||||||||||||||||
| ## 为什么升级? | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. **Apache HttpClient 5.x 是最新稳定版本**:提供更好的性能和更多的功能 | ||||||||||||||||||
| 2. **HttpClient 4.x 已经进入维护模式**:不再积极开发新功能 | ||||||||||||||||||
| 3. **更好的安全性**:HttpClient 5.x 包含最新的安全更新和改进 | ||||||||||||||||||
| 4. **向前兼容**:为未来的开发做好准备 | ||||||||||||||||||
|
|
||||||||||||||||||
| ## 支持的 HTTP 客户端 | ||||||||||||||||||
|
|
||||||||||||||||||
| | HTTP 客户端 | 版本 | 配置值 | 状态 | 说明 | | ||||||||||||||||||
| |------------|------|--------|------|------| | ||||||||||||||||||
| | Apache HttpClient 5.x | 5.5 | `HttpComponents` | ⭐ 推荐 | 最新稳定版本 | | ||||||||||||||||||
| | Apache HttpClient 4.x | 4.5.13 | `HttpClient` | ✅ 支持 | 向后兼容 | | ||||||||||||||||||
| | OkHttp | 4.12.0 | `OkHttp` | ✅ 支持 | 需自行添加依赖 | | ||||||||||||||||||
| | Jodd-http | 6.3.0 | `JoddHttp` | ✅ 支持 | 需自行添加依赖 | | ||||||||||||||||||
|
|
||||||||||||||||||
| ## 模块支持情况 | ||||||||||||||||||
|
|
||||||||||||||||||
| | 模块 | HttpClient 5.x 支持 | 默认客户端 | | ||||||||||||||||||
| |------|-------------------|-----------| | ||||||||||||||||||
| | weixin-java-mp(公众号) | ✅ 是 | HttpComponents (5.x) | | ||||||||||||||||||
| | weixin-java-cp(企业微信) | ✅ 是 | HttpComponents (5.x) | | ||||||||||||||||||
|
||||||||||||||||||
| | weixin-java-cp(企业微信) | ✅ 是 | HttpComponents (5.x) | | |
| | weixin-java-cp(企业微信) | ⚠️ 视集成方式而定 | 参考对应 starter 配置 | |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
迁移指南中的版本号示例使用了 4.7.9.B,但 README.md 文档开头显示当前最新正式版本是 4.7.0。
建议:
- 如果
4.7.9.B是计划发布的版本号,应该在文档中明确说明 - 或者使用占位符如
4.7.x或最新版本来避免混淆
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
迁移指南提到「MiniApp 模块的 HttpClient 5.x 实现正在开发中」,但在代码变更中已经为 MiniApp 的多个 HttpClientType 枚举添加了 HttpComponents 选项。
这种不一致可能导致用户困惑:
- 如果 MiniApp 真的不支持 5.x,不应该在枚举中提供该选项
- 如果已经部分支持(例如核心实现已完成但 starter 配置未完成),文档应该更准确地说明
建议明确说明当前的支持状态和限制。
| A: MiniApp 模块的 HttpClient 5.x 实现正在开发中,将在未来版本中提供。目前 MiniApp 模块会继续使用 HttpClient 4.x。 | |
| ### Q: 我可以在同一个项目中同时使用两个版本吗? | |
| A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如,MP 模块使用 HttpClient 5.x,MiniApp 模块使用 HttpClient 4.x。 | |
| A: MiniApp 模块在核心 SDK 中已经提供了基于 HttpClient 5.x(`HttpComponents`)的支持,但默认仍会使用 HttpClient 4.x(`HttpClient`)。如果你使用的是框架集成(例如 Spring Boot Starter),相关自动配置可能暂未默认切换到 5.x,此时可以通过显式配置 `http-client-type=HttpComponents` 或关注后续版本说明。 | |
| ### Q: 我可以在同一个项目中同时使用两个版本吗? | |
| A: 可以。不同的模块可以配置使用不同的 HTTP 客户端。例如,MP 模块使用 HttpClient 5.x,MiniApp 模块默认使用 HttpClient 4.x,但也可以按需配置为 HttpClient 5.x。 |
Copilot
AI
Dec 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
迁移指南中再次提到版本号 4.7.9.B,与之前的问题相同。为了文档的准确性和可维护性,建议使用更通用的版本号表示方式。
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -136,6 +136,7 @@ | |
|
|
||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
| <httpclient.version>4.5.13</httpclient.version> | ||
| <httpclient5.version>5.5</httpclient5.version> | ||
| <jetty.version>9.4.57.v20241219</jetty.version> <!-- 这个不能用10以上的版本,不支持jdk8--> | ||
| </properties> | ||
| <dependencyManagement> | ||
|
|
@@ -157,13 +158,14 @@ | |
| <version>4.12.0</version> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <!-- HttpClient 5.x - 默认依赖(推荐使用) --> | ||
| <dependency> | ||
| <groupId>org.apache.httpcomponents.client5</groupId> | ||
| <artifactId>httpclient5</artifactId> | ||
| <version>5.5</version> | ||
| <scope>provided</scope> | ||
| <version>${httpclient5.version}</version> | ||
| </dependency> | ||
|
Comment on lines
+161
to
166
|
||
|
|
||
| <!-- HttpClient 4.x - 默认依赖(为了保持向后兼容) --> | ||
| <dependency> | ||
| <groupId>org.apache.httpcomponents</groupId> | ||
| <artifactId>httpclient</artifactId> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,7 +7,11 @@ | |
| */ | ||
| public enum HttpClientType { | ||
| /** | ||
| * HttpClient | ||
| * HttpClient (Apache HttpClient 4.x) | ||
| */ | ||
| HttpClient | ||
| HttpClient, | ||
| /** | ||
| * HttpComponents (Apache HttpClient 5.x) | ||
| */ | ||
| HttpComponents, | ||
|
Comment on lines
9
to
+16
|
||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,4 +19,8 @@ public enum HttpClientType { | |||||
| * JoddHttp. | ||||||
| */ | ||||||
| JoddHttp, | ||||||
| /** | ||||||
| * HttpComponents (Apache HttpClient 5.x). | ||||||
|
||||||
| * HttpComponents (Apache HttpClient 5.x). | |
| * HttpComponents. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -19,4 +19,8 @@ public enum HttpClientType { | |||||
| * JoddHttp. | ||||||
| */ | ||||||
| JoddHttp, | ||||||
| /** | ||||||
| * HttpComponents (Apache HttpClient 5.x). | ||||||
|
||||||
| * HttpComponents (Apache HttpClient 5.x). | |
| * HttpComponents. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
README 配置示例中使用了
HttpComponents(PascalCase),这与部分模块的枚举命名一致,但与 multi-spring-boot-starter 模块中的HTTP_COMPONENTS(UPPER_SNAKE_CASE)命名不一致。这可能会让用户在配置 multi-starter 时感到困惑,因为文档示例使用的是单体 starter 的命名风格。
建议在文档中明确说明:
HttpComponentsHTTP_COMPONENTS或者统一两种 starter 的枚举命名风格。