I cant find any resource to understand how cookies are set by the Http response in Android. I am hitting a URL and reading the response like so:
HttpGet httpGet = new HttpGet(url);
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
String entityStr = EntityUtils.toString(entity);
}
I am told that Http response will set a cookie that will be read by another service later. Is there anything that I need to do to ensure the cookie is set? How can I verify that the cookie is being set. Thanks.
If you are using a client which extends AbstractHttpClient, such as DefaultHttpClient you can do the following to get the cookies after executing the request.
List<Cookie> cookiejar = client.getCookieStore().getCookies();
来源:https://stackoverflow.com/questions/16927536/android-http-response-cookie-store