-
-
Save shohei/96f05e82a5c088d5fdda284340842fe2 to your computer and use it in GitHub Desktop.
Retrofit2/OkHttp3 Cookies (Drag and Drop, One Size Fits 99%)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// By Nikhil Jha | |
// License MIT | |
// DON'T ADD THIS FILE TO YOUR OTHER CLASSES | |
// THIS IS AN EXAMPLE TO TEACH YOU HOW TO MAKE REQUESTS WITH THE MAGIC COOKIES | |
OkHttpClient client = new OkHttpClient(); | |
OkHttpClient.Builder builder = new OkHttpClient.Builder(); | |
builder.addInterceptor(new AddCookiesInterceptor(context)); // VERY VERY IMPORTANT | |
builder.addInterceptor(new ReceivedCookiesInterceptor(context)); // VERY VERY IMPORTANT | |
client = builder.build(); | |
Retrofit retrofit = new Retrofit.Builder() | |
.baseUrl("my-base") // REQUIRED | |
.client(client) // VERY VERY IMPORTANT | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build(); // REQUIRED | |
Your.ThingyClass = retrofit.create(Your.ThingyClass.class); | |
Call<...> call = yourclass.somecall(new yourclass(example, example)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment