cURL to Java
Paste any curl command and get ready-to-run Java code — Java 11+ HttpClient, OkHttp, or Apache HttpClient 5.
About cURL to Java Converter
This tool converts any curl command into
equivalent Java code. It supports three popular output styles: the built-in Java 11+ HttpClient from the java.net.http package (no external dependencies), the widely used OkHttp library, and
enterprise-favorite Apache HttpClient 5.
Everything runs 100% in your browser — your commands, tokens, and API keys never leave your
device. Parsing handles multi-line commands with backslash continuation, single and double
quotes, headers, JSON bodies, form fields, basic auth, cookies, user-agent, referer, TLS
options, and more. The generated class is a complete, runnable Main with the correct imports so you can paste
and run it right away.
How to Use cURL to Java Converter
- Paste your curl command on the left (works with multi-line commands using
\continuations), or click Load Sample to try it out. - Pick your output style: Java 11+ HttpClient, OkHttp, or Apache HttpClient 5. The code updates as you type or change options.
- Review the Java code on the right — a complete, runnable class with the method, headers, body, and auth mapped from your curl command.
- Copy the result with the Copy button and paste it into your project. Add
the matching dependency (OkHttp or Apache HttpClient 5) to your
pom.xmlorbuild.gradle; the Java 11+ HttpClient option needs no dependency at all.
Supported curl Flags
Request
-X / --request— HTTP method-H / --header— request headers-d / --data / --data-raw— body-F / --form— multipart form-G / --get— force GET-I / --head— HEAD request
Options
-u / --user— basic auth-A / --user-agent-e / --referer-b / --cookie-L / --location— follow redirects-k / --insecure— skip TLS verify--compressed
Common Use Cases
- API integration: Drop in a curl example from API docs (Stripe, OpenAI, GitHub, Twilio) and get working Java code instantly.
- Spring Boot & microservices: Turn curl snippets into HttpClient or OkHttp calls for service-to-service requests and integration tests.
- Android development: Generate OkHttp code — the de-facto HTTP client on Android — straight from a curl command.
- Dependency-free clients: Use the Java 11+ HttpClient output when you want HTTP without adding any third-party library.
- Learning Java HTTP: See how the same request maps to HttpClient, OkHttp, and Apache HttpClient side by side.
Frequently Asked Questions
Which Java output style should I pick?
Use Java 11+ HttpClient when you want zero dependencies — it ships with
the JDK in the java.net.http package and works
for both sync and async. Pick OkHttp for Android or when you want a
battle-tested, ergonomic client with connection pooling and interceptors. Pick Apache HttpClient 5 for enterprise apps that need fine-grained control
over connection management, proxies, and authentication.
What Java version does the HttpClient output need?
The java.net.http.HttpClient API was added in
Java 11, so the HttpClient output requires Java 11 or newer. The OkHttp and Apache
HttpClient outputs run on Java 8+ as long as the corresponding library is on your
classpath.
Does this tool handle multi-line curl commands?
Yes. Backslash + newline continuations (\ at
the end of a line) are joined before parsing, so you can paste curl commands exactly as
they appear in documentation or in the output of "Copy as cURL" from browser DevTools.
How are JSON request bodies handled?
The JSON body from -d is emitted as a properly
escaped Java string and sent with the request. Because Java has no native JSON literal,
the body is kept as a string — set the matching Content-Type: application/json header (the tool
preserves it from your curl command) so the server parses it correctly.
Is multipart form data (-F) supported?
Yes for OkHttp and Apache HttpClient 5, which have native multipart builders
(MultipartBody and MultipartEntityBuilder). The Java 11+
HttpClient has no built-in multipart support, so for -F it falls back to a urlencoded body with a
note — switch to OkHttp or Apache for true multipart uploads. For file uploads
(-F file=@path), replace the generated text part
with a file part before running.
How is basic auth (-u user:pass) converted?
For OkHttp it becomes an Authorization header
built with Credentials.basic(user, pass). For
the Java 11+ HttpClient and Apache HttpClient, the tool adds an Authorization: Basic header with the
base64-encoded credentials so it works without extra configuration.
Is my curl command sent to a server?
No. Parsing and code generation run entirely in your browser using JavaScript. Your curl commands — including any API tokens, bearer tokens, or cookies — never leave your device, so it's safe to use with production credentials.
Should I use -k / --insecure in production?
No. -k disables TLS certificate verification
and exposes you to man-in-the-middle attacks. Because disabling verification in Java
requires a custom SSLContext, the tool emits a
note instead of trust-all code — keep certificate verification enabled for any code that
ships to production.
Which dependencies do I need?
The Java 11+ HttpClient output needs no dependency — it's part of the
JDK. For OkHttp, add com.squareup.okhttp3:okhttp.
For Apache HttpClient 5, add org.apache.httpcomponents.client5:httpclient5 (plus httpclient5-fluent / httpmime-equivalent for multipart).