Home / Cost tools / cURL converter / Java
cURL to Java converter
Paste a cURL command and get the same request in Java, using java.net.http (Java 11 and later). It converts in your browser; nothing you paste is sent anywhere.
Converted in your browser. Nothing you paste is stored or sent, so a command with your API key in it stays on your machine.
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
HttpClient client = HttpClient.newBuilder()
.build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://api.scraper.example/v1/scrape?url=https%3A%2F%2Fshop.example.com%2Fproducts%3Fpage%3D2&render_js=true&country=us"))
.header("Authorization", "Bearer YOUR_API_KEY")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.statusCode());
System.out.println(response.body());
}
} Running the code
It uses java.net.http, built into Java 11 and later; save it as Main.java and run java Main.java. Each header is one .header call on the request builder.
Where java.net.http differs from curl
Java's HttpClient does not follow redirects unless it is built with followRedirects, which the code adds for -L. send blocks until the whole body has arrived.
What calls like this one cost
The example is a scraping API call with JavaScript rendering on and a country chosen. 100,000 of them a month cost from $49.00 on ScrapeBadger, and the same pages without rendering from $19.00 on BrowserCloud, the cheapest complete bills across 27 web scraping APIs this site prices from their own pages. What rendering adds on each API