我试图登录到网站,并保持该会话/ cookie的,这样服务器会识别出我的登录信息,但我在努力搞清楚提取响应中的cookie,并设置为保持我的登录请求的方式.我想知道我是否应该采用标题"Set-Cookie"或使用CookieStore.任何帮助是极大的赞赏.这是我的代码,其中包含我认为getHeader/getCookie方法的注释.
public class Http
{
DefaultHttpClient client = new DefaultHttpClient();
HttpGet request;
HttpEntity entity;
HttpResponse response;
HttpPost post;
CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
public static void setContext()
{
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}
public static void getPage(String url) throws Exception
{
request = new HttpGet(url);
response = client.execute(request, localContext);
PARSER.preParse(url, response);
}
public static HttpResponse postPage(List<NameValuePair> params, String host, String action) throws Exception
{
post = new HttpPost(host + action);
post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
response = client.execute(post, …Run Code Online (Sandbox Code Playgroud)