0

Or how else would you write something like this?

@Headers(
        "$CONTENT_TYPE:${BodyContentType.JSON}",
        "$AUTHORIZATION:Bearer {jwt}"
)
@POST("/some/where")
fun something(@Path("jwt")jwt:String, @Body somethingRequest:JsonObject):Call<JsonObject>

(which results in

java.lang.IllegalArgumentException: URL "/some/where" does not contain "{jwt}". (parameter #1)

)

User1291
  • 7,664
  • 8
  • 51
  • 108
  • Possible duplicate of [Android Retrofit Parameterized @Headers](https://stackoverflow.com/questions/18478258/android-retrofit-parameterized-headers) – user2340612 Feb 27 '19 at 19:27
  • Try to look at https://stackoverflow.com/a/29885004/6235974 – Merov Feb 28 '19 at 00:06

1 Answers1

0

According to the documentation: https://square.github.io/retrofit/2.x/retrofit/index.html?retrofit2/http/Header.html there is the @Header annotation.

So in your case it would be:

fun something(@Header("jwt")jwt:String, @Body somethingRequest:JsonObject):Call<JsonObject>
Pasukaru
  • 1,050
  • 1
  • 10
  • 22
  • There are two issues with the `@Header` annotation. One: It's impossible to add multiple headers with the same name. Two: It requires that the full header value is provided as a string value. So in your example, the `"jwt"` needs be changed to `"authorization"` and the `jwt:String` must ACTUALLY contain `"Bearer " + jwtToken` – User1291 Mar 06 '19 at 14:17
  • As stated in the documentation, the Header annotation also supports List and array types, i.e: fun something(@Header("jwt") jwt: List,...) Regarding the second problem, yes, it think there is no support for templating. You would have to parse this yourself. – Pasukaru Mar 06 '19 at 15:56