android - 快速 Android 网络 cookie 问题
问题描述
我在我的 Android 项目中使用Fast Android Networking,我想在其中使用 Cookie。当我在没有 Cookies 类的情况下设置库时,请求正常并且工作顺利,但是当我添加自定义 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
解决方案
推荐阅读
- sql - SQL拆分字符串并结合第一次和第二次出现
- continuous-integration - TeamCity:在自定义构建中使用配置参数
- c# - INotifyDataErrorInfo(有时)不起作用
- python - 下面如何计算 dy(Tensorflow 中的上游梯度)?
- swift - SwiftUI - 如何获取一定范围内的随机数
- javascript - Graphql查询变量在reactjs中没有更新
- amazon-web-services - 无法设置云端 cookie
- jquery - 在数据表jQuery中更改复选框状态为true的类按钮
- autocomplete - 如何将 React admin AutoCompleteInput 与远程数据一起使用?
- php - dockerfile 连接外部数据库