okhttp / okhttp3 / ResponseBody / string

string

fun string(): String

Returns the response as a string.

If the response starts with a Byte Order Mark (BOM), it is consumed and used to determine the charset of the response bytes.

Otherwise if the response has a Content-Type header that specifies a charset, that is used to determine the charset of the response bytes.

Otherwise the response bytes are decoded as UTF-8.

This method loads entire response body into memory. If the response body is very large this may trigger an OutOfMemoryError. Prefer to stream the response body if this is a possibility for your response.