Convert a cURL GET request to Java

Paste any curl GET command and get clean Java code using OkHttp. Runs entirely in your browser — headers, auth, and JSON bodies map to idiomatic Java.

Quick answer

To convert a cURL command to Java, paste it into the Toolpaper workbench below. It parses the command in your browser and emits idiomatic Java code — headers, query string, request body, authentication (Bearer, Basic, API key), and cookies are all wired up automatically. No data is uploaded; conversion is fully client-side.

Prefer a different target? See the full cURL to Java reference, or jump to the same guide in JavaScript, Node.js, or Python.

InputcURL command
MethodGET·Headers1·Body—· Chars 71
OutputJVM · OkHttp(modern JVM)
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class Main {
  public static void main(String[] args) throws Exception {
    OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
    clientBuilder.followRedirects(false).followSslRedirects(false);
    OkHttpClient client = clientBuilder.build();
    Request.Builder rb = new Request.Builder().url("https://api.example.com/users/42");
    rb.method("GET", null);
    rb.header("Accept", "application/json");
    try (Response response = client.newCall(rb.build()).execute()) {
      System.out.println(response.body().string());
    }
  }
}
Inspect

Example

A representative curl command for this scenario. Paste your own above to convert an exact match.

curl input
curl https://api.example.com/users/42 \
  -H "Accept: application/json"

Implementation notes

  • Request-line method (GET) and target URL are extracted from the curl command exactly as written — no case-folding, no path rewriting.
  • Every -H header maps to a Java header entry; duplicates are preserved so servers that read multi-valued headers keep behaving.
  • Query strings in the URL stay in the URL; -G with --data-urlencode is promoted to a structured params argument where OkHttp supports it.
  • TLS flags (--insecure, --cacert, --cert) surface as inline notes so you don't ship an insecure client to production by accident.

Common mistakes

  • Forgetting that -X GET without a body still sends an empty body — the generated code mirrors that exactly.
  • Assuming curl auto-follows redirects: it doesn't. Add -L (or the generator's follow-redirects flag) if you actually need to chase 3xx responses.
  • Copying a Cookie header from DevTools that already encodes session state — use the Clean panel to strip session cookies before you share.

Common questions

How do I send a GET request in Java?
Paste your curl GET command above. Toolpaper generates Java using OkHttp with headers, query string, and (where applicable) request body wired up.
Does the GET generator handle authentication?
Yes — Authorization headers, Bearer tokens, Basic auth (-u), and API keys pass through to the generated Java code unchanged.
Is my curl sent to a server?
No. Parsing and code generation run in your browser. Nothing is uploaded.
Can I also convert this to other languages?
Yes. Once you paste your command, the language picker lets you switch between 18 targets (fetch, axios, Python, Go, PHP, Ruby, Rust, Java, Kotlin, C#, PowerShell, Swift and more).

More cURL methods in Java

Java hub →

The same guide in other languages

All guides →

Full Java reference on the cURL to Java hub, or open the main converter for all 18 targets.