In my android application, I am migrating to okhttp and need to setup the PHPSESSID manually for logged-in users in the default cookieStore, so that they don't get logged out. I am manually setting the cookie using the following code.
((CookieManager)client.getCookieHandler()).getCookieStore().add(new URI("http://www.example.com"), new HttpCookie("PHPSESSID", getPhpSessionID()));
The cookie seems to be set cause I can get the cookie back using this code
((CookieManager)client.getCookieHandler()).getCookieStore().get(new URI("http://www.example.com"));
However, when I am executing the client call using
Request request = new Request.Builder().url("http://www.example.com/getdata.php").build();
client.newCall(request).execute();
The cookies are not being sent in the request (verified this network call using android proxy).
Whats the correct way to set such a cookie so that okhttp client uses that cookie?