我需要从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保存在某种容器中。这可能吗?