Okhttp3 – RequestBody.create(contentType, content) Deprecated

Java Solution:
Use create(String, MediaType) instead of create(MediaType, String) for example

Kotlin Solution:
Use the extension function content.toRequestBody(contentType);
for the File type file.asRequestBody(contentType)

Note:
I’m using kotlin, but my IDE just doesn’t automatically import the class or method like import okhttp3.RequestBody.Companion.toRequestBody, so I import it manually…then use it as the example given by Saeed Younus and Pratyesh below

For more: The documentation

(In Android Studio or any Jetbrain’s IDE, the solution to the deprecated methods or class can be found by just holding the Ctrl and clicking on the create(...) of RequestBody.create)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)