我正在使用okhttp 3.0.1.
每个地方我都用okhttp2来处理cookie的例子
OkHttpClient client = new OkHttpClient(); CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); client.setCookieHandler(cookieManager);
可以请一些指导我如何在版本3中使用.setCookieHandler方法不存在于版本3中.
解决方法
现在我正在玩它
尝试 PersistentCookieStore,为JavaNetCookieJar添加渐变依赖:
尝试 PersistentCookieStore,为JavaNetCookieJar添加渐变依赖:
编译“com.squareup.okhttp3:okhttp-urlconnection:3.0.0-RC1”
和init
// init cookie manager CookieHandler cookieHandler = new CookieManager( new PersistentCookieStore(ctx),CookiePolicy.ACCEPT_ALL); // init okhttp 3 logger HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); // init OkHttpClient OkHttpClient httpClient = new OkHttpClient.Builder() .cookieJar(new JavaNetCookieJar(cookieHandler)) .addInterceptor(logging) .build();
`