java.lang.Object
org.miaixz.bus.http.plugin.httpz.HttpRequest
- Direct Known Subclasses:
DeleteRequest,GetRequest,HeadRequest,PostRequest,PutRequest
An abstract base class for representing an HTTP request. It encapsulates common request properties such as URL,
parameters, headers, and body, and provides a template for building the final Httpd
Request object.- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringThe request body as a raw string (e.g., for JSON).protected Request.BuilderThe builder for the final Httpd Request.The pre-encoded request parameters.The request headers.protected StringThe unique identifier for this request.protected List<MultipartFile> A list of files for multipart uploads.protected MultipartBodyThe multipart body for file uploads.The request parameters (e.g., for form submissions or query strings).protected StringThe request URL. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedHttpRequest(String url, Object tag, Map<String, String> params, Map<String, String> headers, List<MultipartFile> list, String body, MultipartBody multipartBody, String id) Constructs an HttpRequest.protectedHttpRequest(String url, Object tag, Map<String, String> params, Map<String, String> encodedParams, Map<String, String> headers, List<MultipartFile> list, String body, MultipartBody multipartBody, String id) Constructs an HttpRequest with both standard and pre-encoded parameters. -
Method Summary
Modifier and TypeMethodDescriptionBuilds aRequestCall, which is the executable representation of this request.protected abstract RequestbuildRequest(RequestBody requestBody) Abstract method to be implemented by subclasses to construct the finalRequestobject with the correct HTTP method.protected abstract RequestBodyAbstract method to be implemented by subclasses to construct the specific request body (e.g., for POST, PUT).createRequest(Callback callback) Creates the finalRequestobject.static RequestBodycreateRequestBody(org.miaixz.bus.core.lang.MediaType contentType, InputStream is) A static factory method to create aRequestBodyfrom anInputStream.getId()Gets the unique identifier for this request.protected voidheaders()Appends the configured headers to the internalRequest.Builder.
-
Field Details
-
id
The unique identifier for this request. -
url
The request URL. -
body
The request body as a raw string (e.g., for JSON). -
params
The request parameters (e.g., for form submissions or query strings). -
encodedParams
The pre-encoded request parameters. -
headers
The request headers. -
multipartBody
The multipart body for file uploads. -
list
A list of files for multipart uploads. -
builder
The builder for the final Httpd Request.
-
-
Constructor Details
-
HttpRequest
protected HttpRequest(String url, Object tag, Map<String, String> params, Map<String, String> headers, List<MultipartFile> list, String body, MultipartBody multipartBody, String id) Constructs an HttpRequest.- Parameters:
url- The request URL.tag- A tag for the request, used for cancellation.params- The request parameters.headers- The request headers.list- A list of files for multipart uploads.body- The raw request body string.multipartBody- The multipart body.id- The unique request identifier.
-
HttpRequest
protected HttpRequest(String url, Object tag, Map<String, String> params, Map<String, String> encodedParams, Map<String, String> headers, List<MultipartFile> list, String body, MultipartBody multipartBody, String id) Constructs an HttpRequest with both standard and pre-encoded parameters.- Parameters:
url- The request URL.tag- A tag for the request, used for cancellation.params- The standard request parameters.encodedParams- The pre-encoded request parameters.headers- The request headers.list- A list of files for multipart uploads.body- The raw request body string.multipartBody- The multipart body.id- The unique request identifier.
-
-
Method Details
-
createRequestBody
public static RequestBody createRequestBody(org.miaixz.bus.core.lang.MediaType contentType, InputStream is) A static factory method to create aRequestBodyfrom anInputStream.- Parameters:
contentType- The media type of the content.is- The input stream to read from.- Returns:
- A new
RequestBodyinstance. - Throws:
NullPointerException- if the input stream is null.
-
buildRequestBody
Abstract method to be implemented by subclasses to construct the specific request body (e.g., for POST, PUT).- Returns:
- The constructed
RequestBody.
-
buildRequest
Abstract method to be implemented by subclasses to construct the finalRequestobject with the correct HTTP method.- Parameters:
requestBody- The request body to be used.- Returns:
- The final
Requestobject.
-
build
Builds aRequestCall, which is the executable representation of this request.- Parameters:
httpd- TheHttpdclient instance.- Returns:
- A new
RequestCall.
-
createRequest
Creates the finalRequestobject. This is a convenience method that combines building the request body and the request itself.- Parameters:
callback- The callback for the request (not used in this implementation).- Returns:
- The constructed
Request.
-
headers
protected void headers()Appends the configured headers to the internalRequest.Builder. -
getId
Gets the unique identifier for this request.- Returns:
- The request ID string.
-