Class OAuth2HttpClient
java.lang.Object
cloud.opencode.base.oauth2.http.OAuth2HttpClient
- All Implemented Interfaces:
AutoCloseable
OAuth2 HTTP Client
OAuth2 HTTP 客户端
HTTP client wrapper for OAuth2 operations using JDK HttpClient.
使用 JDK HttpClient 的 OAuth2 操作 HTTP 客户端包装器。
Features | 主要功能:
- JDK HttpClient integration - JDK HttpClient 集成
- Form URL encoded requests - 表单 URL 编码请求
- JSON response handling - JSON 响应处理
- Timeout configuration - 超时配置
Usage Examples | 使用示例:
// Used internally by OAuth2Client
// 由OAuth2Client内部使用
OAuth2HttpClient client = new OAuth2HttpClient(config);
String response = client.post(tokenUrl, params);
Security | 安全性:
- Thread-safe: Yes (stateless after construction) - 线程安全: 是(构造后无状态)
- Null-safe: Yes (validates inputs) - 空值安全: 是(验证输入)
- Since:
- JDK 25, opencode-base-oauth2 V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new OAuth2 HTTP client with default settings 使用默认设置创建新的 OAuth2 HTTP 客户端OAuth2HttpClient(OAuth2Config config) Create a new OAuth2 HTTP client from config 从配置创建新的 OAuth2 HTTP 客户端OAuth2HttpClient(Duration connectTimeout, Duration readTimeout) Create a new OAuth2 HTTP client with custom timeouts 使用自定义超时创建新的 OAuth2 HTTP 客户端 -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Send a GET request 发送 GET 请求Send a POST request with form-encoded body 发送带有表单编码正文的 POST 请求Send a POST request with form-encoded body and headers 发送带有表单编码正文和头的 POST 请求
-
Constructor Details
-
OAuth2HttpClient
public OAuth2HttpClient()Create a new OAuth2 HTTP client with default settings 使用默认设置创建新的 OAuth2 HTTP 客户端 -
OAuth2HttpClient
-
OAuth2HttpClient
Create a new OAuth2 HTTP client from config 从配置创建新的 OAuth2 HTTP 客户端- Parameters:
config- the OAuth2 config | OAuth2 配置
-
-
Method Details
-
postForm
-
postForm
Send a POST request with form-encoded body and headers 发送带有表单编码正文和头的 POST 请求- Parameters:
url- the URL | URLparams- the form parameters | 表单参数headers- additional headers | 附加头- Returns:
- the response body | 响应正文
- Throws:
OAuth2Exception- on HTTP errors | HTTP 错误时抛出
-
get
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-