cURL to Java
Paste a curl command and get Java code using HttpClient — or pick any other language.
Paste a curl command above to generate code
How curl maps to Java (HttpClient)
- →Uses java.net.http.HttpClient (Java 11+), no extra libraries.
- →Java refuses to set Host, Connection, Content-Length, Expect and Upgrade itself, so those curl headers are left out.
- →The body goes through HttpRequest.BodyPublishers.ofString; use ofFile for an upload from disk.
Frequently asked
Why do I get "restricted header name" in Java?
HttpClient manages Host, Connection, Content-Length and a few others itself and throws if you set them. The converter drops them; the client sends correct values automatically.
Can I use this with Java 8?
No — java.net.http arrived in Java 11. On Java 8 use HttpURLConnection or a library like OkHttp or Apache HttpClient.