相关疑难解决方法(0)

在Android Q中不推荐使用PreferenceManager getDefaultSharedPreferences

PreferenceManager getDefaultSharedPreferences已在Android Q中弃用,该如何替换?

android sharedpreferences android-10.0

28
推荐指数
4
解决办法
6914
查看次数

添加cookie以改进2请求

我需要在改装2.0中添加cookie.如果我理解正确,cookie - 与标题相同.必须添加此Cookie:

private HashMap<String, String> cookies = new HashMap();
cookies.put("sessionid", "sessionId");
cookies.put("token", "token");
Run Code Online (Sandbox Code Playgroud)

这个与Jsoup lib一起使用:

String json = Jsoup.connect(apiURL + "/link")
                    .cookies(cookies)
                    .ignoreHttpErrors(true)
                    .ignoreContentType(true)
                    .execute()
                    .body();
Run Code Online (Sandbox Code Playgroud)

这是我的代码与改造请求:

@GET("link")
Call<CbGet> getData(@Header("sessionid") String sessionId, @Header("token") String token);
Run Code Online (Sandbox Code Playgroud)

但它不起作用...我得到403错误代码,所以请求中没有cookie ...

任何的想法?

cookies android retrofit retrofit2

14
推荐指数
3
解决办法
2万
查看次数