Answer the question
In order to leave comments, you need to log in
How to get Request Cookie on Retrofit?
Hello, I am writing an application on Android Studio. There is a server, there are requests that I send from the client through Retrofit. How can I get a Request Cookie?
Answer the question
In order to leave comments, you need to log in
public class ReceivedCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Response originalResponse = chain.proceed(chain.request());
if (!originalResponse.headers("Set-Cookie").isEmpty()) {
// ...
}
return originalResponse;
}
}
OkHttpClient.Builder okHttpClient = new OkHttpClient().newBuilder();
okHttpClient.interceptors().add(new ReceivedCookiesInterceptor());
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient.build())
.addConverterFactory(GsonConverterFactory.create())
.build();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question