0

我需要从中获取 cookie DefaultHttpClient,将它们传递给 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://..");

我也想把饼干放在某种容器里。这可能吗?

4

0 回答 0