---
date_published: 2026-10-08
date_modified: 2026-10-08
canonical_url: https://metricshub.org/simple-http-java/index.html
---

# HTTP Java Client

The Simple HTTP Java Client is a lightweight Java library designed to simplify the execution of HTTP requests. It leverages Java's built-in HttpURLConnection, requires no external dependencies, and supports multiple HTTP methods including GET, POST, PUT, and DELETE.

## Features

- **Easy Integration**: No external dependencies, making it easy to integrate into your Java projects.
- **HTTPS Support**: Handles HTTPS connections with customizable TLS protocols.
- **Proxy Configuration**: Easily configure proxy settings if needed.
- **Authentication**: Supports basic authentication for both the target URL and proxy.
- **Customizable Headers**: Add additional headers to your HTTP requests.
- **User-Agent Configuration**: Set your own User-Agent or use the default one.
- **Download Support**: Download content directly to a file with optional file path customization.
- **Timeout Handling**: Set timeout limits for connection and read operations.

## Usage

Simply add HTTP in the list of dependencies in your [Maven pom.xml](https://maven.apache.org/pom.html):

```xml
<dependencies>
	<!-- [...] -->
	<dependency>
		<groupId>org.metricshub</groupId>
		<artifactId>simple-http-java</artifactId>
		<version>1.0.03</version>
	</dependency>
</dependencies>
```

Then, invoke the HTTP Client as follows:

```java
package org.metricshub.http;

import java.io.IOException;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {

		final String url = "https://httpbin.org/anything";
		final String method = "GET";
		final String[] specifiedSslProtocols = null;
		final String username = null;
		final char[] password = null;
		final String proxyServer = null;
		final int proxyPort = -1;
		final String proxyUsername = null;
		final char[] proxyPassword = null;
		final String userAgent = null;
		final Map<String, String> headers = Map.of("accept", "application/json");
		final String body = null;
		final int timeout = 10;
		final String downloadToPath = null;

		final HttpResponse response = HttpClient.sendRequest(
			url,
			method,
			specifiedSslProtocols,
			username,
			password,
			proxyServer,
			proxyPort,
			proxyUsername,
			proxyPassword,
			userAgent,
			headers,
			body,
			timeout,
			downloadToPath
		);

		System.out.format("HTTP Response Status: %d%n", response.getStatusCode());
		System.out.format("HTTP Response Headers:%n%s", response.getHeader());
		System.out.format("HTTP Response Body:%n%s%n", response.getBody());
	}
}
```

> Note: When using JRE 21, encountering the error message `java.lang.NoSuchMethodError: 'void sun.net.www.protocol.http.AuthCacheValue.setAuthCache(sun.net.www.protocol.http.AuthCache)` indicates that your application is not configured to leverage multi-release JARs. The *HTTP Java Client* supports Java 21 and beyond by defining an updated version of the `ThreadSafeNoCacheAuthenticator` that is located in `META-INF/versions/21`. Depending on how your application works, it may be necessary to set `Multi-Release` to true in the JAR manifest.
