您的位置:首页 > 理论基础 > 计算机网络

How to handle the session in HttpClient 4.1

2012-10-19 21:32 369 查看
The correct way is to prepare a
CookieStore
which you need to set in the
HttpContext
which you in turn pass on every
HttpClient#execute()
call.

HttpClient httpClient = new DefaultHttpClient();
CookieStore cookieStore = new BasicCookieStore();
HttpContext httpContext = new BasicHttpContext();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
// ...

HttpResponse response1 = httpClient.execute(method1, httpContext);
// ...

HttpResponse response2 = httpClient.execute(method2, httpContext);
// ...
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: