Module bus.http

Class PostRequest

java.lang.Object
org.miaixz.bus.http.plugin.httpz.HttpRequest
org.miaixz.bus.http.plugin.httpz.PostRequest

public class PostRequest extends HttpRequest
Represents an HTTP POST request. This class encapsulates parameters and builds the appropriate RequestBody, handling URL-encoded forms, multipart file uploads, and raw body content.
Since:
Java 17+
Author:
Kimi Liu
  • Constructor Details

    • PostRequest

      public PostRequest(String url, Object tag, Map<String,String> params, Map<String,String> headers, List<MultipartFile> list, String body, MultipartBody multipartBody, String id)
      Constructs a new PostRequest.
      Parameters:
      url - The request URL.
      tag - A tag for this request.
      params - The form parameters.
      headers - The request headers.
      list - A list of files for multipart upload.
      body - A raw string for the request body.
      multipartBody - A pre-built multipart body.
      id - A unique identifier for this request.
    • PostRequest

      public PostRequest(String url, Object tag, Map<String,String> params, Map<String,String> encoded, Map<String,String> headers, List<MultipartFile> list, String body, MultipartBody multipartBody, String id)
      Constructs a new PostRequest with both standard and pre-encoded parameters.
      Parameters:
      url - The request URL.
      tag - A tag for this request.
      params - The standard form parameters.
      encoded - The pre-encoded form parameters.
      headers - The request headers.
      list - A list of files for multipart upload.
      body - A raw string for the request body.
      multipartBody - A pre-built multipart body.
      id - A unique identifier for this request.
  • Method Details

    • buildRequestBody

      protected RequestBody buildRequestBody()
      Builds the request body based on the provided parameters. The priority is as follows: 1. A pre-built MultipartBody if provided. 2. A new MultipartBody if files are added. 3. A raw string body if provided. 4. A URL-encoded FormBody as the default.
      Specified by:
      buildRequestBody in class HttpRequest
      Returns:
      The constructed RequestBody.
    • buildRequest

      protected Request buildRequest(RequestBody requestBody)
      Description copied from class: HttpRequest
      Abstract method to be implemented by subclasses to construct the final Request object with the correct HTTP method.
      Specified by:
      buildRequest in class HttpRequest
      Parameters:
      requestBody - The request body to be used.
      Returns:
      The final Request object.