반응형

@Header 어노테이션 

 

1. 헤더 어노테이션을 추가하여 전송.

 

interface api {

@GET("/api/itemlist")

  fun itemList(

  @Header("token") token: String?,

  @Query("wid") wid : Int ): Call<List<ItemListResponseData>>

}

 

 

 

2. Interceptor를 이용하여 전송 

https://blog.codavel.com/how-to-create-an-http-interceptor-for-an-android-app-using-okhttp3

class AppInterceptor : Interceptor {

@Throws(IOException::class)

override fun intercept(chain: Interceptor.Chain) : Response = with(chain) {

                 val newRequest = request().newBuilder()

                .addHeader("(Key)", "(Value)")

                .build()

 

                proceed(newRequest)

   }

}

 

 

반응형

+ Recent posts