Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Okhttp3 in Kotlin, String.mediaType() does not work

This is the code that I am trying to do but it doesn't work.

 val JSON = String.format("application/json; charset=utf-8").toMediaType()
  (headers as Map<String, String>).toHeaders()

I did import: import okhttp3.MediaType What do I need to do to make it recognise the toMediaType and toHeaders methods?

like image 341
rosu alin Avatar asked Jan 01 '23 18:01

rosu alin


2 Answers

Adding the import to my gradle file to force version 4.7.2 solved it

implementation "com.squareup.okhttp3:okhttp:4.7.2"
like image 70
Nicolas Duponchel Avatar answered Jan 03 '23 06:01

Nicolas Duponchel


The extension functions are in companion objects:

import okhttp3.MediaType.Companion.toMediaType
import okhttp3.Headers.Companion.toHeaders
like image 21
laalto Avatar answered Jan 03 '23 08:01

laalto