Package kong.unirest.core
Class HttpRequestBody
- java.lang.Object
-
- kong.unirest.core.BaseRequest<HttpRequestWithBody>
-
- kong.unirest.core.HttpRequestBody
-
- All Implemented Interfaces:
HttpRequest<HttpRequestWithBody>
,HttpRequestWithBody
class HttpRequestBody extends BaseRequest<HttpRequestWithBody> implements HttpRequestWithBody
-
-
Constructor Summary
Constructors Constructor Description HttpRequestBody(Config config, HttpMethod method, java.lang.String url)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RequestBodyEntity
body(byte[] body)
Set a byte array as the body of the requestRequestBodyEntity
body(java.io.InputStream body)
Set a InputStream as the bodyRequestBodyEntity
body(java.lang.Object body)
Set a Object as the body of the request.RequestBodyEntity
body(java.lang.String body)
Set a String as the body of the requestRequestBodyEntity
body(JSONElement body)
Sugar method for body operationRequestBodyEntity
body(JsonNode body)
Set JSON on the bodyHttpRequestBody
charset(java.nio.charset.Charset charset)
Set the Charset encoding for the Content-Type.HttpRequestWithBody
contentType(java.lang.String type)
MultipartBody
field(java.lang.String name, java.io.File file)
Sets a File on the body.MultipartBody
field(java.lang.String name, java.io.File file, java.lang.String contentType)
Sets a File on the body with a specified content-type.MultipartBody
field(java.lang.String name, java.io.InputStream stream, java.lang.String fileName)
Sets a File on the body from a raw InputStream requires a file name.MultipartBody
field(java.lang.String name, java.io.InputStream stream, ContentType contentType, java.lang.String fileName)
Sets a File on the body from a raw InputStream requires a specified content-type and file name.MultipartBody
field(java.lang.String name, java.lang.Object value)
Sets a field param on the body.MultipartBody
field(java.lang.String name, java.lang.Object value, java.lang.String contentType)
Sets a field param on the body with a specified content-type.MultipartBody
field(java.lang.String name, java.util.Collection<?> value)
Sets multiple field params on the body each with the same name.MultipartBody
fields(java.util.Map<java.lang.String,java.lang.Object> parameters)
Sets multiple field params on the body from a map of key/value pairs.java.util.Optional<Body>
getBody()
java.nio.charset.Charset
getCharset()
get the current default charsetMultipartBody
multiPartContent()
Forces the request to send as multipart even if all params are simple-
Methods inherited from class kong.unirest.core.BaseRequest
accept, asBytes, asBytesAsync, asBytesAsync, asEmpty, asEmptyAsync, asEmptyAsync, asFile, asFileAsync, asFileAsync, asJson, asJsonAsync, asJsonAsync, asObject, asObject, asObject, asObjectAsync, asObjectAsync, asObjectAsync, asObjectAsync, asObjectAsync, asPaged, asString, asStringAsync, asStringAsync, basicAuth, connectTimeout, cookie, cookie, cookie, downloadMonitor, equals, getConnectTimeout, getCreationTime, getHeaders, getHttpMethod, getObjectMapper, getPath, getUrl, getVersion, hashCode, header, headerReplace, headers, headersReplace, queryString, queryString, queryString, responseEncoding, routeParam, routeParam, thenConsume, thenConsumeAsync, toSummary, version, withObjectMapper
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface kong.unirest.core.HttpRequest
accept, asBytes, asBytesAsync, asBytesAsync, asEmpty, asEmptyAsync, asEmptyAsync, asFile, asFileAsync, asFileAsync, asJson, asJsonAsync, asJsonAsync, asObject, asObject, asObject, asObjectAsync, asObjectAsync, asObjectAsync, asObjectAsync, asObjectAsync, asPaged, asString, asStringAsync, asStringAsync, basicAuth, connectTimeout, cookie, cookie, cookie, downloadMonitor, getConnectTimeout, getCreationTime, getHeaders, getHttpMethod, getUrl, getVersion, header, headerReplace, headers, headersReplace, queryString, queryString, queryString, responseEncoding, routeParam, routeParam, thenConsume, thenConsumeAsync, toSummary, version, withObjectMapper
-
Methods inherited from interface kong.unirest.core.HttpRequestWithBody
noCharset
-
-
-
-
Constructor Detail
-
HttpRequestBody
public HttpRequestBody(Config config, HttpMethod method, java.lang.String url)
-
-
Method Detail
-
field
public MultipartBody field(java.lang.String name, java.util.Collection<?> value)
Description copied from interface:HttpRequestWithBody
Sets multiple field params on the body each with the same name.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the fieldvalue
- a Collection of values- Returns:
- this request builder
-
field
public MultipartBody field(java.lang.String name, java.io.File file)
Description copied from interface:HttpRequestWithBody
Sets a File on the body.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the file fieldfile
- the file- Returns:
- this request builder
-
field
public MultipartBody field(java.lang.String name, java.io.File file, java.lang.String contentType)
Description copied from interface:HttpRequestWithBody
Sets a File on the body with a specified content-type.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the file fieldfile
- the filecontentType
- contentType (i.e. image/png)- Returns:
- this request builder
-
field
public MultipartBody field(java.lang.String name, java.lang.Object value)
Description copied from interface:HttpRequestWithBody
Sets a field param on the body.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the fieldvalue
- a values- Returns:
- this request builder
-
field
public MultipartBody field(java.lang.String name, java.lang.Object value, java.lang.String contentType)
Description copied from interface:HttpRequestWithBody
Sets a field param on the body with a specified content-type.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the fieldvalue
- the objectcontentType
- contentType (i.e. application/xml)- Returns:
- this request builder
-
fields
public MultipartBody fields(java.util.Map<java.lang.String,java.lang.Object> parameters)
Description copied from interface:HttpRequestWithBody
Sets multiple field params on the body from a map of key/value pairs.- Specified by:
fields
in interfaceHttpRequestWithBody
- Parameters:
parameters
- the map of field params- Returns:
- this request builder
-
field
public MultipartBody field(java.lang.String name, java.io.InputStream stream, ContentType contentType, java.lang.String fileName)
Description copied from interface:HttpRequestWithBody
Sets a File on the body from a raw InputStream requires a specified content-type and file name.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the file fieldstream
- the inputStreamcontentType
- contentType (i.e. image/png)fileName
- the name for the file- Returns:
- this request builder
-
multiPartContent
public MultipartBody multiPartContent()
Description copied from interface:HttpRequestWithBody
Forces the request to send as multipart even if all params are simple- Specified by:
multiPartContent
in interfaceHttpRequestWithBody
- Returns:
- The same MultipartBody
-
field
public MultipartBody field(java.lang.String name, java.io.InputStream stream, java.lang.String fileName)
Description copied from interface:HttpRequestWithBody
Sets a File on the body from a raw InputStream requires a file name.- Specified by:
field
in interfaceHttpRequestWithBody
- Parameters:
name
- the name of the file fieldstream
- the inputStreamfileName
- the name for the file- Returns:
- this request builder
-
charset
public HttpRequestBody charset(java.nio.charset.Charset charset)
Description copied from interface:HttpRequestWithBody
Set the Charset encoding for the Content-Type. This is appended to the Content-Type Header (e.g. application/x-www-form-urlencoded; charset=US-ASCII) Default is UTF-8- Specified by:
charset
in interfaceHttpRequestWithBody
- Parameters:
charset
- the charset- Returns:
- this request builder
-
body
public RequestBodyEntity body(JsonNode body)
Description copied from interface:HttpRequestWithBody
Set JSON on the body- Specified by:
body
in interfaceHttpRequestWithBody
- Parameters:
body
- the JsonNode- Returns:
- this request builder
-
body
public RequestBodyEntity body(java.lang.String body)
Description copied from interface:HttpRequestWithBody
Set a String as the body of the request- Specified by:
body
in interfaceHttpRequestWithBody
- Parameters:
body
- the String- Returns:
- this request builder
-
body
public RequestBodyEntity body(java.io.InputStream body)
Description copied from interface:HttpRequestWithBody
Set a InputStream as the body- Specified by:
body
in interfaceHttpRequestWithBody
- Parameters:
body
- the Object- Returns:
- this request builder
-
body
public RequestBodyEntity body(java.lang.Object body)
Description copied from interface:HttpRequestWithBody
Set a Object as the body of the request. This will be serialized with one of the following methods: - Strings are native - JSONElements use their native toString - Everything else will pass through the supplied ObjectMapper- Specified by:
body
in interfaceHttpRequestWithBody
- Parameters:
body
- the Object- Returns:
- this request builder
-
body
public RequestBodyEntity body(byte[] body)
Description copied from interface:HttpRequestWithBody
Set a byte array as the body of the request- Specified by:
body
in interfaceHttpRequestWithBody
- Parameters:
body
- the byte[]- Returns:
- this request builder
-
body
public RequestBodyEntity body(JSONElement body)
Sugar method for body operation- Specified by:
body
in interfaceHttpRequestWithBody
- Parameters:
body
- raw JSONElement- Returns:
- RequestBodyEntity instance
-
getCharset
public java.nio.charset.Charset getCharset()
Description copied from interface:HttpRequestWithBody
get the current default charset- Specified by:
getCharset
in interfaceHttpRequestWithBody
- Returns:
- the Charset
-
contentType
public HttpRequestWithBody contentType(java.lang.String type)
- Specified by:
contentType
in interfaceHttpRequestWithBody
- Parameters:
type
- The content mime type- Returns:
- this request builder
-
getBody
public java.util.Optional<Body> getBody()
- Specified by:
getBody
in interfaceHttpRequest<HttpRequestWithBody>
- Returns:
- if the request has a body it will be here.
-
-