Interface RequestBody
- All Known Implementing Classes:
FileBody, FormBody, JsonBody, MultipartBody, RequestBody.SimpleBody
public interface RequestBody
Request Body - HTTP Request Body Interface
请求体 - HTTP 请求体接口
Defines the contract for HTTP request bodies with content type and body publisher support.
定义 HTTP 请求体的契约,支持内容类型和 body publisher。
Features | 主要功能:
- Content type abstraction - 内容类型抽象
- JDK HttpClient BodyPublisher integration - JDK HttpClient BodyPublisher 集成
- Factory methods for common body types - 常见请求体类型的工厂方法
- Support for JSON, XML, text, and file bodies - 支持 JSON、XML、文本和文件请求体
Usage Examples | 使用示例:
// JSON body
RequestBody body = RequestBody.json("{\"key\":\"value\"}");
// Text body
RequestBody body = RequestBody.text("Hello World");
// File body
RequestBody body = RequestBody.file(Path.of("data.csv"));
Security | 安全性:
- Thread-safe: Yes (implementations should be immutable) - 线程安全: 是(实现应为不可变)
- Null-safe: No (content must not be null) - 空值安全: 否(内容不能为 null)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic RequestBodyempty()static RequestBodystatic RequestBodydefault longstatic RequestBodystatic RequestBodystatic RequestBodystatic RequestBodystatic RequestBodystatic RequestBody
-
Method Details
-
getContentType
String getContentType() -
getBodyPublisher
HttpRequest.BodyPublisher getBodyPublisher() -
getContentLength
default long getContentLength() -
empty
-
of
-
of
-
of
-
json
-
text
-
xml
-
file
-
file
-