# HttpSession

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 a real web browser.

`HttpSession` is a tool just for that. It sends requests for you, handles 301 and 302 redirections automatically, reads and preserves cookies across the requests, and so on.

Usage is simple:

```java
HttpSession session = new HttpSession();

HttpRequest request = HttpRequest.get("www.facebook.com");
session.sendRequest(request);

// request is sent, and response is received

// process the HTML page
String page = session.getPage();

// create a new request
HttpRequest newRequest = HttpRequest.post(formAction);

session.sendRequest(newRequest);
```

`HttpSession` instance handles all the cookies, allowing the session to be tracked while browsing using HTTP and supports keep-alive persistent connections.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://http.jodd.org/httpsession.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
