简体   繁体   中英

Is it possible to pass http response from Java to browser?

I got a page by apache HttpClient

CookieStore cookieStore = new BasicCookieStore();
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

HttpGet request = new HttpGet("http://mywebsite.com");
request.addHeader("User-Agent",  "Mozilla/5.0");

HttpClient client = HttpClientBuilder.create().build();
try {
    HttpResponse response = client.execute(request, localContext);

} catch (IOException e) {
    e.printStackTrace();
}

I need click a link in this page manually

Can I pass the whole response (html, session, cookie) to browser? so that I can complete the remaining process.

Here's a similar question which will get you cookies in Firefox: Passing Cookies from Java to Browser

As for passing your session, probably not possible although maybe you could do the same thing with the Firefox database. It certainly wouldn't be a "plug and play" solution nor would it be guaranteed to work across versions.

"Passing the HTML" could be done by creating a web server in Java. There are some libraries that you can use for this.

However, all of these things are hacky and will not work in most situations.

An alternative would be to use HtmlUnit to click the link from within your program, without ever opening a real browser.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM