---
title: "cURL to Java Converter: HttpClient and OkHttp"
description: "Free curl to Java converter: paste a curl command, get Java 11+ HttpClient or OkHttp code. Gzip, -F uploads, restricted headers and proxies handled."
canonical: "https://browser-use.com/tools/curl-to-java"
last_updated: "2026-11-21"
---

# cURL to Java Converter: HttpClient and OkHttp

## cURL to Java Converter

Convert a curl command to Java HttpClient or OkHttp code that compiles. Gzip, file uploads and headers Java refuses are handled, and every change is listed.

## How it works

### Copy the request as cURL

In Chrome, Edge or Firefox DevTools, right-click a request in the Network panel and choose Copy as cURL. Bash and Windows cmd copies both work.

### Pick HttpClient or OkHttp

HttpClient ships with Java 11. OkHttp is a separate library. JSON bodies become text blocks (Java 15+); untick that for Java 11.

### Run it

Save it as Main.java. HttpClient code runs with java Main.java. OkHttp code needs its jars on the classpath, or Maven or Gradle.

### Which headers does HttpClient refuse?

Connection, Content-Length, Expect, Host and Upgrade: setting one throws IllegalArgumentException, so the code leaves them out and says so.

Source: [java.net.http: jdk.httpclient.allowRestrictedHeaders](https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/module-summary.html) · [HttpRequest.Builder](https://docs.oracle.com/en/java/javase/17/docs/api/java.net.http/java/net/http/HttpRequest.Builder.html)

### Is a gzip response decompressed?

HttpClient does not do it, so with --compressed the code asks for gzip and unzips it. OkHttp unzips gzip itself.

Source: [GZIPInputStream](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/zip/GZIPInputStream.html) · [OkHttp BridgeInterceptor](https://github.com/square/okhttp/blob/parent-4.12.0/okhttp/src/main/kotlin/okhttp3/internal/http/BridgeInterceptor.kt)

### What happens to redirects?

With -L, HttpClient code follows up to 50 like curl (or your --max-redirs); OkHttp stops at 20. Without -L, neither follows.

Source: [java.net.http: jdk.httpclient.redirects.retrylimit](https://docs.oracle.com/en/java/javase/21/docs/api/java.net.http/module-summary.html) · [OkHttp RetryAndFollowUpInterceptor](https://github.com/square/okhttp/blob/parent-4.12.0/okhttp/src/main/kotlin/okhttp3/internal/http/RetryAndFollowUpInterceptor.kt) · [curl --max-redirs](https://curl.se/docs/manpage.html#--max-redirs)

### What about files and -k?

\-d @file and -F file=@path are read when the code runs. -k is flagged, never turned into code that trusts every certificate. Anything not converted is listed.

### Is my command sent anywhere?

No. Conversion runs in this tab. Copied commands often carry cookies and tokens, so treat the code like a password.

## Request blocked?

Browser Use cloud browsers run a maintained Chromium fork with residential proxies.

[See stealth browsers](https://browser-use.com/stealth-browsers)

curl command

Java client

HttpClient (Java 11+)OkHttp

Text blocks for JSON (Java 15+)

Convert to JavaLoad example

---

BROWSER USE

- Browser Use Agents: give Browser Use a task and receive completed work. API V4 is current for new integrations.
- Browser Infrastructure: connect your agent or automation to managed browsers through SDK, REST, or CDP. Starts at $0.06/browser-hour.
- Developer tools: Open Source, Browser Harness, SDK, and MCP support the two products above.

[Developer Index](https://browser-use.com/index.md)
[Product Map](https://browser-use.com/llms.txt)
[Full Product Context](https://browser-use.com/llms-full.txt)
[Pricing](https://browser-use.com/pricing.md)
[Cloud Docs](https://docs.browser-use.com/cloud/quickstart)
[Open Source Docs](https://docs.browser-use.com/open-source/introduction)
