Home > Mobile >  Android Okhttp3 Cookie value leakage problems
Android Okhttp3 Cookie value leakage problems

Time:10-13

If (singleton==null) {
Synchronized (HttpUtil. Class) {
If (singleton==null) {

The singleton=new OkHttpClient. Builder ()
ConnectTimeout (10, TimeUnit. SECONDS)
ReadTimeout (20, TimeUnit. SECONDS)
AddInterceptor (new LoggingInterceptor ())
CookieJar (new cookieJar () {
Private final HashMap CookieStore=new HashMap<> (a);

@ 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 ());
System. The out. Println (" Cookies======="+ Cookies);
Return the cookies!=null? Cookies: new ArrayList (a);
}
}). The build ();
}
}
}
The debug code to run to the cookieStore. Get (url. The host ()) has a value, code to run to cookieStore. Put (url. Host (), cookies); The cookie value is missing, advice on how to deal with?

CodePudding user response:

Make sure the server returns a response whether contains cookies

CodePudding user response:

reference m - 1/f, oj response:
first to make sure that the server returns the response contains cookies

The role of this code is run to cookieStore. Put (url. The host (), cookies); The server returns the cookie value when saved to the local, and then to loadForRequest HttpUrl (url) to save the cookie value when used to request, cookieStore. Put (url. The host (), cookies); No value if the back-end didn't return the cookie value, so lost my cookies?

CodePudding user response:

There's a possibility, so want you to confirm it
  • Related