HttpBrowser
Sending requests and receiving responses is not enough when we have to emulate browsing through a website. For example, we might need to login, capture, and carry-on the cookies to preserve the session, follow the redirects, make requests to get dynamic content... in the same way as in the real Internet browser.
HttpBrowser is a tool just for that. It sends requests for you; handles 301 and 302 redirections automatically, reads and preserve cookies across the requests, and so on.
Usage is simple:
1
HttpBrowser browser = new HttpBrowser();
2
​
3
HttpRequest request = HttpRequest.get("www.facebook.com");
4
browser.sendRequest(request);
5
​
6
// request is sent and response is received
7
​
8
// process the HTML page
9
String page = browser.getPage();
10
​
11
// create new request
12
HttpRequest newRequest = HttpRequest.post(formAction);
13
​
14
browser.sendRequest(newRequest);
Copied!
HttpBrowser instance handles all the cookies, allowing the session to be tracked while browsing using HTTP and supports keep-alive persistent connections.
Last modified 1yr ago
Export as PDF
Copy link