Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retrofit 2 @headers error in kotlin

I try to add multiple static headers with retrofit 2 (2.3.0) like this :

interface WeatherAPI {

    @Headers({
        "Accept: application/json",
        "Content-type:application/json"
    })
    @GET("/data/2.5/weather")
    fun getWeatherForCityName(@Query("q") city: String, @Query("appid") appid: String) : Call<GetWeatherResponse>;

}

I have the folowing error :

error

Any idea of my mistake?

like image 518
ooCHURIoo Avatar asked Feb 28 '18 10:02

ooCHURIoo


2 Answers

Use below code:

@Headers(
        "Accept: application/json",
        "Content-type:application/json"
)
like image 56
Android Team Avatar answered Nov 12 '22 09:11

Android Team


Braces {} isn't needed inside @Headers.

Docs: https://kotlinlang.org/docs/reference/annotations.html#arrays-as-annotation-parameters

like image 42
osipxd Avatar answered Nov 12 '22 10:11

osipxd