快速的Android网络Cookie问题

时间:2018-07-14 07:28:40

标签: android android-networking

我在Android项目中使用Fast Android Networking,并且我想在其中使用Cookies。当我设置没有Cookie类的库时,请求可以正常运行,但是当我添加自定义Cookies处理程序时,请求突然停止工作,而不会引发任何错误或执行任何其他操作。

可能是什么问题?正在使用的代码如下:

CookieJar cookieJar = new CookieJar()
    {
        @Override
        public void saveFromResponse(HttpUrl url, List<Cookie> cookies)
        {
            appCtx.setCookies(url.host(), cookies); //custom storage based on SharedPrefs
        }

        @Override
        public List<Cookie> loadForRequest(HttpUrl url)
        {
            List<Cookie> cookieList = appCtx.getCookies(url.host());
            return cookieList;
        }
    };

//if I use the below, the client hangs without doing anything
OkHttpClient httpClient = new OkHttpClient().newBuilder()
    .cookieJar(cookieJar)
    .build();
AndroidNetworking.initialize(ctx, httpClient);

//if I skip the above and simply apply the below, requests go through smoothly. 
// Note, am only using one at a time, and commenting out the other
AndroidNetworking.initialize(ctx);

//then continue as usual
AndroidNetworking.setParserFactory(new JacksonParserFactory());
... //other code

0 个答案:

没有答案