cURL converter · Java
cURL to Java
Paste a curl command and get a compilable OkHttp snippet. We wire -X into .method(...), map -F files to MultipartBody.addFormDataPart, forward --max-time to callTimeout, and translate -x proxy://host:port into an InetSocketAddress proxy.
InputcURL command
1 secret
MethodPOST·Headers2·Body46 B· Chars 187
OutputJVM · OkHttp(modern JVM)
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
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();
RequestBody body = RequestBody.create("{\"to\":\"+15551234567\",\"body\":\"Hello from curl\"}", MediaType.parse("application/json"));
Request.Builder rb = new Request.Builder().url("https://api.example.com/v1/messages");
rb.method("POST", body);
rb.header("Authorization", "Bearer sk_test_123");
rb.header("Content-Type", "application/json");
try (Response response = client.newCall(rb.build()).execute()) {
System.out.println(response.body().string());
}
}
}Inspect
Top guides for Java
All guides →Common questions
- Why OkHttp and not HttpURLConnection?
- OkHttp is the de-facto standard: connection pooling, HTTP/2, timeouts, and a fluent Request builder. HttpURLConnection is verbose and hard to get right for POST bodies.
- Does it handle multipart uploads?
- Yes. -F name=@file becomes RequestBody.create(new File(...), MediaType.parse(...)) inside a MultipartBody.Builder, with the content type preserved when provided.
- What about --insecure?
- We intentionally do not emit a trust-all TrustManager — that's a foot-gun for production code. A comment points to where you'd wire one in for local dev.
- Is my curl sent anywhere?
- No. Parsing and code generation happen entirely in your browser.
Also convert cURL to
All guides →Same parser, same idiomatic output — swap the target language whenever your stack changes. Every hub carries its own reference guides for methods, payloads, and auth.