How to add headers to OkHttp request interceptor?

前端 未结 10 1539
感情败类
感情败类 2020-12-01 00:24

I have this interceptor that i add to my OkHttp client:

public class RequestTokenInterceptor implements Interceptor {
@Override
public Response intercept(Cha         


        
10条回答
  •  猫巷女王i
    2020-12-01 01:11

    If you are using Retrofit library then you can directly pass header to api request using @Header annotation without use of Interceptor. Here is example that shows how to add header to Retrofit api request.

    @POST(apiURL)
    void methodName(
            @Header(HeadersContract.HEADER_AUTHONRIZATION) String token,
            @Header(HeadersContract.HEADER_CLIENT_ID) String token,
            @Body TypedInput body,
            Callback callback);
    

    Hope it helps!

提交回复
热议问题