toResponseBody

fun String.toResponseBody(contentType: MediaType? = null): ResponseBody

Returns a new response body that transmits this string. If contentType is non-null and has a charset other than utf-8 the behaviour differs by platform.

On the JVM the encoding will be used instead of utf-8.

On non JVM platforms, this method will fail for encodings other than utf-8.


fun ByteArray.toResponseBody(contentType: MediaType? = null): ResponseBody

Returns a new response body that transmits this byte array.


fun ByteString.toResponseBody(contentType: MediaType? = null): ResponseBody

Returns a new response body that transmits this byte string.