Okhttp3 - RequestBody.create(contentType, content) Deprecated

后端 未结 6 1952
清酒与你
清酒与你 2020-12-29 17:57

I did not find any example of how to replace the deprecation method. The examples on the okhttp3 main page are old. This is one of them:

public static final          


        
6条回答
  •  失恋的感觉
    2020-12-29 18:06

    You need to import these files manually may be this is a bug in android studio. It is not suggested but this is work for Okhttp 4.2.2

    import okhttp3.MediaType.Companion.toMediaTypeOrNull
    import okhttp3.RequestBody.Companion.asRequestBody
    

    and use as

    val file = File("path")
    file.asRequestBody("image/jpeg".toMediaTypeOrNull())
    

提交回复
热议问题