更新时间:2023-02-17 15:40:29
从这个页面阅读以下部分:关于Cookie和状态管理的HttpClient教程
3.8。 HTTP状态管理和执行上下文
3.9。每用户/线程状态管理
Read the following sections from this page: HttpClient Tutorial about Cookies and state management 3.8. HTTP state management and execution context 3.9. Per user / thread state management
这可能是您想要的代码:
and this maybe that code you want:
HttpClient httpclient = new DefaultHttpClient();
// Create a local instance of cookie store
CookieStore cookieStore = new BasicCookieStore();
// Create local HTTP context
HttpContext localContext = new BasicHttpContext();
// Bind custom cookie store to the local context
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
HttpGet httpget = new HttpGet("http://www.google.com/");
// Pass local context as a parameter
HttpResponse response = httpclient.execute(httpget, localContext);