Android:Http响应cookie存储 [英] Android: Http response cookie store
问题描述
我找不到任何资源来了解Android中Http响应如何设置cookie.我点击了一个URL,然后像这样读取响应:
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);
}
有人告诉我Http响应将设置一个cookie,以后将由另一个服务读取.我需要做些什么来确保已设置cookie?如何验证cookie是否已设置. 谢谢.
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.
推荐答案
如果您使用的客户端扩展了 DefaultHttpClient ,您可以执行以下操作以在执行请求后获取Cookie.
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();
这篇关于Android:Http响应cookie存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!