Skip to content

Instantly share code, notes, and snippets.

@leeyc09
Created January 26, 2016 02:31
Show Gist options
  • Save leeyc09/2d5fc0c73638042e90f3 to your computer and use it in GitHub Desktop.
Save leeyc09/2d5fc0c73638042e90f3 to your computer and use it in GitHub Desktop.
import java.io.IOException;
import java.util.HashSet;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
public class AddCookiesInterceptor implements Interceptor {
@Override
public Response intercept(Chain chain) throws IOException {
Request.Builder builder = chain.request().newBuilder();
//프리퍼런스에서 쿠키 값을 불러 옵니다.
HashSet<String> preferences = (HashSet) PreferenceHelper.getDefaultPreferences().getStringSet(PreferenceHelper.PREF_directfolder_COOKIES, new HashSet<>());
int count = 1;
for (String cookie : preferences) {
builder.addHeader("Cookie" + count, cookie);
count++;
}
return chain.proceed(builder.build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment