Android Okhttp3 的坑

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

//记录下正确姿势
OkHttpClient mHttpClient = new OkHttpClient.Builder().cookieJar(new CookieJar() {
    private final HashMap> cookieStore = new HashMap<>();
    //Tip:這裡key必須是String
    @Override
    public void saveFromResponse(HttpUrl url, List cookies) {
        cookieStore.put(url.host(), cookies);
    }
    @Override
    public List loadForRequest(HttpUrl url) {
        List cookies = cookieStore.get(url.host());
        return cookies != null ? cookies : new ArrayList();
    }
}).build();

转载于:https://my.oschina.net/u/3136970/blog/907365

你可能感兴趣的:(Android Okhttp3 的坑)