Reputation: 191
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 :
Any idea of my mistake?
Upvotes: 16
Views: 16444
Reputation: 123
You should use:
@Headers(value = ["Accept: application/json",
"Content-type:application/json"])
because the headers need an array parameter for it, you are using the wrong syntax in kotlin
Upvotes: 8
Reputation:
Use below code:
@Headers(
"Accept: application/json",
"Content-type:application/json"
)
Upvotes: 23
Reputation: 1228
Braces {}
isn't needed inside @Headers
.
Docs: https://kotlinlang.org/docs/reference/annotations.html#arrays-as-annotation-parameters
Upvotes: 45