I am sending a POST request using the volley library on android. Once I get the json response the server is sending back a cookie in the headers. I can see the cookie when I check the network traffic using the profiler in android studio.
I need to be able to get the cookie from the header and assign it to a variable so that I can pass it to the next activity.
I have looked at Using cookies with Android volley library and how to get cookies from volley response
They are both several years old and I was unable to get them to work. I am not sure if it is because they use a GET request and mine is a POST request.
Is there a simple way to get the cookie from the server response?
This is the code that I currently have in place, all is well except for grabbing the cookie.
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, cartUrl, jsonParams,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//Obviously this will not work becuase .getCookie() requires a url as a parameter
//There must be a method something like this to capture the response and get the cookie.
String chocolateChip = CookieManager.getInstance().getCookie(response);
startActivity(postIntent);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
postRequestQue.add(postRequest);
}
from capture cookie from volley json response
No comments:
Post a Comment