java.lang.Object
org.miaixz.bus.http.plugin.httpz.RequestBuilder<PostBuilder>
org.miaixz.bus.http.plugin.httpz.PostBuilder
A builder for creating HTTP POST requests using a fluent interface. It supports setting URL, parameters, headers, a
raw request body, and multipart file uploads.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a file to the multipart request from a byte array.An alias foraddFile(String, String, byte[]).Adds a file to the multipart request from aFileobject.addFile(String partName, String fileName, InputStream is) Adds a file to the multipart request from anInputStream.Adds a file to the multipart request from a string, using the default UTF-8 encoding.Adds a file to the multipart request from a string with a specified charset.Sets a raw string as the request body.build()Abstract method to be implemented by subclasses to build the final, executable request call.multipartBody(MultipartBody multipartBody) Sets a pre-constructedMultipartBody.Methods inherited from class org.miaixz.bus.http.plugin.httpz.RequestBuilder
addEncoded, addEncoded, addHeader, addHeader, addParam, addParam, addParam, id, tag, url
-
Constructor Details
-
PostBuilder
Constructs a newPostBuilder.- Parameters:
httpd- TheHttpdclient instance.
-
-
Method Details
-
build
Description copied from class:RequestBuilderAbstract method to be implemented by subclasses to build the final, executable request call.- Specified by:
buildin classRequestBuilder<PostBuilder>- Returns:
- The constructed
RequestCall.
-
body
Sets a raw string as the request body. This is typically used for sending content like JSON or XML. The 'Content-Type' header should be set accordingly.- Parameters:
body- The raw string content for the request body.- Returns:
- This builder instance for chaining.
-
multipartBody
Sets a pre-constructedMultipartBody. This allows for advanced multipart request configuration.- Parameters:
multipartBody- The pre-built multipart body.- Returns:
- This builder instance for chaining.
-
addFile
Adds a file to the multipart request from a byte array.- Parameters:
partName- The name of the form field.fileName- The name of the file.content- The file content as a byte array.- Returns:
- This builder instance for chaining.
-
addFile
Adds a file to the multipart request from anInputStream.- Parameters:
partName- The name of the form field.fileName- The name of the file.is- The input stream providing the file's content.- Returns:
- This builder instance for chaining.
-
addFile
Adds a file to the multipart request from aFileobject.- Parameters:
partName- The name of the form field.fileName- The name of the file.file- The file to be uploaded.- Returns:
- This builder instance for chaining.
-
addFile
public PostBuilder addFile(String partName, String fileName, String content) throws UnsupportedEncodingException Adds a file to the multipart request from a string, using the default UTF-8 encoding.- Parameters:
partName- The name of the form field.fileName- The name of the file.content- The string content of the file.- Returns:
- This builder instance for chaining.
- Throws:
UnsupportedEncodingException- if UTF-8 is not supported.
-
addFile
public PostBuilder addFile(String partName, String fileName, String content, String charsetName) throws UnsupportedEncodingException Adds a file to the multipart request from a string with a specified charset.- Parameters:
partName- The name of the form field.fileName- The name of the file.content- The string content of the file.charsetName- The name of the charset to use for encoding.- Returns:
- This builder instance for chaining.
- Throws:
UnsupportedEncodingException- if the specified charset is not supported.
-
addFile
An alias foraddFile(String, String, byte[]).- Parameters:
partName- The name of the form field.fileName- The name of the file.content- The file content as a byte array.charsetName- This parameter is ignored.- Returns:
- This builder instance for chaining.
-