Android : Set custom CookieManager while using Volley?

on Friday, July 25, 2014


I ported to Volley and I realized that it doesn't manage cookies. I then looked for an answer on how to do so, and the best so far is it of setting the default CookieHandler in the static method setDefault of the class CookieHandler. I created then a new CookieManager as suggested in many questions with my custom CookieStore, but when I tried queuing a request I get this stacktrace:



07-26 00:27:04.509: E/Volley(11414): [22379] NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException

07-26 00:27:04.509: E/Volley(11414): java.lang.NullPointerException

07-26 00:27:04.509: E/Volley(11414): at java.net.CookieManager.get(CookieManager.java:112)

07-26 00:27:04.509: E/Volley(11414): at com.android.okhttp.internal.http.HttpEngine.prepareRawRequestHeaders(HttpEngine.java:540)

07-26 00:27:04.509: E/Volley(11414): at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:184)

07-26 00:27:04.509: E/Volley(11414): at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)

07-26 00:27:04.509: E/Volley(11414): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)

07-26 00:27:04.509: E/Volley(11414): at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)

07-26 00:27:04.509: E/Volley(11414): at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:109)

07-26 00:27:04.509: E/Volley(11414): at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)

07-26 00:27:04.509: E/Volley(11414): at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:110)


I'm using a Moto G with Android 4.4.2 to debug, and I set the CookieManager in the Application object (in the onCreate method). I guess I'm not missing anything. I'd really appreciate some ideas to solve this problem, or some workaround! Thanks in advance


0 comments:

Post a Comment