# FAQ

### How to save a binary file?

```java
final String link =
    "https://repo1.maven.org/maven2" +
    "/org/jodd/jodd-http/3.9.1/jodd-http-3.9.1.jar";

HttpResponse response = HttpRequest
    .get(link)
    .send();

byte[] bytes = response.bodyBytes();

FileUtil.writeBytes(
    new File(SystemUtil.userHome(), "jodd-http.jar"), bytes);
```

### How to follow multi redirects?

Either use `HttpBrowser`:

```java
HttpBrowser browser = new HttpBrowser();

browser.sendRequest(HttpRequest.get("google.com"));

// read response
Response response = browser.getResponse();
String page = browser.getPage();
```

or the flag `followRedirects()` to enable the following redirects:

```java
HttpResponse response =
    HttpRequest
        .get("google.com")
        .followRedirects(true)
        .send();
```

### What is the difference between HttpRequest and HttpBrowser?

`HttpRequest` represents just a single request; clean and simple.

`HttpBrowser` emulates browsing of a website (i.e. set of URLs) like a browser. Besides sending requests, it also stores and resends cookies, maintaining the current user session. Moreover, the `HttpBrowser` uses new request on redirection following, allows common request headers for all the requests etc.

### Server choses TLSv1.2, but that protocol version is not enabled?

Just add the following property `-Dhttps.protocols=TLSv1.1,TLSv1.2` which configures the JVM to specify which TLS protocol version should be used during HTTPS connections.

Since 8u292, JDK 11.0.11, JDK16+ Java requires use of TLS v1.2 or v1.3.

### SOCKS5: proxy returned 1

This is a common error when using Socks5 behind some VPNs.


---

# 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/faq.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.
