CURL to Java HttpURLConnection Online
This tool helps you to generate Java HttpURLConnection code based on CURL Command. Copy and Paste CURL Command and Generate Java HttpURLConnection.
What can you do with CURL to Java HttpURLConnection Converter Online?
- CURL to Java HttpURLConnection is very unique tool to convert cURL command to Java HttpURLConnection request of Java HttpURLConnection. The input provide by the user's cURL command to generate Java HttpURLConnection Code.
- This tool saves your time and helps to generate Java HttpURLConnection code with ease.
- CURL to Java HttpURLConnection works well on Windows, MAC, Linux, Chrome, Firefox, Edge and Safari.
what is CURL?
cURL is an open-source command line tool that downloads files from the web. It supports a variety of protocols, including Java HttpURLConnection, Java HttpURLConnectionS, FTP, SFTP, TFTP, Gopher and others.
How do convert CURL to Java HttpURLConnection code?
Step1: Paste and convert your CURL requests to Java HttpURLConnection code
Step2: Copy Java HttpURLConnection code
Convert CURL to Java HttpURLConnection example
CURL
curl example.com
Java HttpURLConnection Code
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws IOException {
URL url = new URL("http://example.com");
HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
httpConn.setRequestMethod("GET");
InputStream responseStream = httpConn.getResponseCode() / 100 == 2
? httpConn.getInputStream()
: httpConn.getErrorStream();
Scanner s = new Scanner(responseStream).useDelimiter("\\A");
String response = s.hasNext() ? s.next() : "";
System.out.println(response);
}
}