okhttp / okhttp3 / RequestBody

RequestBody

abstract class RequestBody

Constructors

<init>

RequestBody()

Functions

contentLength

open fun contentLength(): Long

Returns the number of bytes that will be written to sink in a call to writeTo, or -1 if that count is unknown.

contentType

abstract fun contentType(): MediaType?

Returns the Content-Type header for this body.

isDuplex

open fun isDuplex(): Boolean

A duplex request body is special in how it is transmitted on the network and in the API contract between OkHttp and the application.

isOneShot

open fun isOneShot(): Boolean

Returns true if this body expects at most one call to writeTo and can be transmitted at most once. This is typically used when writing the request body is destructive and it is not possible to recreate the request body after it has been sent.

writeTo

abstract fun writeTo(sink: BufferedSink): Unit

Writes the content of this request to sink.

Companion Object Functions

create

fun create(contentType: MediaType?, content: String): RequestBody

Returns a new request body that transmits content. If contentType is non-null and lacks a charset, this will use UTF-8.

fun create(contentType: MediaType?, content: ByteString): RequestBody
fun create(contentType: MediaType?, content: ByteArray, offset: Int = 0, byteCount: Int = content.size): RequestBody

Returns a new request body that transmits content.

fun create(contentType: MediaType?, file: File): RequestBody

Returns a new request body that transmits the content of file.

Inheritors

FormBody

class FormBody : RequestBody

MultipartBody

class MultipartBody : RequestBody

An RFC 2387-compliant request body.