Zero Signup ToolsFree browser tools

Developer Tools

cURL to Java Converter

Convert a curl command to Java code in your browser. Java 11 HttpClient, legacy HttpURLConnection, and OkHttp output with headers, auth, JSON, and forms.

Or load a preset

The curl command is parsed locally in your browser. Tokens, headers, auth values, and request bodies never leave your device.

What gets converted

Method and URL
-X / --request sets the method explicitly. Without it, a body forces POST and -G forces GET with data folded into the URL.
Headers and auth
Every -H becomes a header on the request builder. -u user:pass becomes a Base64 Authorization header (or Credentials.basic in OkHttp), and -b cookies become a Cookie header.
JSON and form bodies
-d values that parse as JSON are emitted inside a Java text block (""") when possible. Form data is sent as a string with a matching Content-Type.
Multipart uploads
-Fparts use OkHttp's MultipartBody with addFormDataPart, because HttpClient and HttpURLConnection have no built-in multipart builder. File fields read from a local File.

How to use

  1. Paste a curl command into the input area, click Load sample, or pick a preset (GET, POST JSON, form login, basic auth, multipart upload, PUT with cookie).
  2. Pick an output style: HttpClient for the JDK 11 standard library, HttpURLConnection for the legacy java.net client, or OkHttp for the popular third-party client.
  3. Read the summary card to confirm the method, URL, header count, and body type the parser detected.
  4. Click Copy code to grab the generated Java class. It is a complete public class with a main method, so paste it into a .java file and run it.
  5. Watch the warnings panel: ignored curl flags are listed by name, and multipart requests note that the OkHttp output is used and which file path to point at a real file.

About this tool

cURL to Java Converter parses a curl command the way a POSIX shell would and emits runnable Java HTTP code in three idiomatic styles. The parser handles single quotes, double quotes with backslash escapes, $'...' ANSI-C quoting, backslash-newline continuations, and glued short flags (-XPOST, -dvalue), so commands copied from a terminal, a runbook, or a browser DevTools "Copy as cURL" paste cleanly. The HttpClient output targets java.net.http.HttpClient (JDK 11 and newer), the modern standard-library client: it builds an HttpRequest with HttpRequest.newBuilder, sets the method with .GET, .POST, .PUT, .DELETE, or the generic .method, carries the body with HttpRequest.BodyPublishers.ofString, sends with client.send and HttpResponse.BodyHandlers.ofString, and applies headers, a Base64 Authorization header for -u basic auth, and a Cookie header for -b. The HttpURLConnection output covers the legacy java.net client that still appears across tutorials, Android code, and corporate codebases: it opens the connection, sets the request method and properties, writes the body through getOutputStream, and reads the response from getInputStream or getErrorStream with a BufferedReader. The OkHttp output uses com.squareup.okhttp3 with OkHttpClient, Request.Builder, RequestBody.create, MediaType.parse, and Credentials.basic, the most widely used third-party Java and Kotlin HTTP client and a common "curl to okhttp" search. JSON bodies are detected by parsing -d / --data and emitted inside a Java text block (the triple-quote string) when the payload is multi-line and safe, so a pasted JSON object stays readable; form-urlencoded bodies are sent as a string with the matching Content-Type. Multipart -F uploads are always built with OkHttp's MultipartBody and addFormDataPart, because HttpClient and HttpURLConnection have no built-in multipart builder, and the converter says so plainly rather than guessing. The -G / --get flag folds data into the URL as a query string, and -k / --insecure becomes a trust-all SSLContext on HttpClient with honest notes on the other two clients. Common boolean flags such as -L, -s, -i, -v, --compressed, and --http2 are recognised and silently ignored because they do not change the request itself, and unknown flags are reported as warnings rather than guessed at. Each output is a complete public class with sorted imports, a main method, and proper response reading, so it compiles as written. Useful for backend engineers porting a curl example from API documentation into a Java or Spring service, Android developers translating a request into OkHttp, SREs turning a debug command into a Java probe, and anyone who has searched "curl to java" or "curl to okhttp" and bounced off a stale or paywalled tool. All parsing and code generation runs in the browser, so curl commands, auth tokens, and request bodies never leave your device.

Free to use. Works in your browser. No signup, no login.

Related tools

You may also like

All tools
All toolsDeveloper Tools