use*_*235 1 android httpresponse httpcookie
我无法找到任何资源来了解如何通过Android中的Http响应设置Cookie.我正在点击一个URL并阅读响应,如下所示:
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);
}
Run Code Online (Sandbox Code Playgroud)
我被告知Http响应将设置一个cookie,稍后将由另一个服务读取.为确保设置cookie,我需要做些什么吗?如何验证cookie是否已设置.谢谢.
如果您使用的是扩展AbstractHttpClient的客户端,例如DefaultHttpClient,则可以执行以下操作以在执行请求后获取cookie.
List<Cookie> cookiejar = client.getCookieStore().getCookies();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5379 次 |
| 最近记录: |