从DefaultHttpClient获取cookie并传递给WebClient

时间:2013-07-27 19:22:07

标签: java

我需要从DefaultHttpClient获取Cookie,将其传递给HtmlUnit的WebClient,然后发送请求。

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.*;
import org.apache.http.impl.client.DefaultHttpClient;

import com.gargoylesoftware.htmlunit.*;
import com.gargoylesoftware.htmlunit.util.*;
import com.gargoylesoftware.htmlunit.html.HtmlPage;

HttpClient apacheClient = new DefaultHttpClient();
HttpResponse apacheResponse;
HttpGet apacheGet;
WebClient htmlUnitClient = new WebClient();
WebRequest htmlUnitRequest;

HttpUriRequest hur = new HttpGet("http://..");
apacheResponse = apacheClient.execute(hur);
// Here I need to get cookies from apacheClient and set them for the next request done with htmlUnitClient
HtmlPage page = htmlUnitClient.getPage("http://..");

我还想将cookie保存在某种容器中。这可能吗?

0 个答案:

没有答案