CURL to Java HttpURLConnection Online
Ovaj alat vam pomaže generirati Java HttpURLConnection kod na temelju CURL naredbe. Kopirajte i zalijepite CURL naredbu i generirajte Java HttpURLConnection.
Što možete učiniti s CURL to Java HttpURLConnection Converter Online?
- CURL u Java HttpURLConnection vrlo je jedinstven alat za pretvaranje cURL naredbe u Java HttpURLConnection zahtjev Java HttpURLConnection. Ulaz koji pruža korisnička naredba cURL za generiranje Java HttpURLConnection koda.
- Ovaj alat štedi vaše vrijeme i pomaže u generiranju Java HttpURLConnection koda s lakoćom.
- CURL to Java HttpURLConection radi dobro na Windows, MAC, Linux, Chrome, Firefox, Edge i Safari.
što je CURL?
cURL je alat naredbenog retka otvorenog koda koji preuzima datoteke s weba. Podržava različite protokole, uključujući Java HttpURLConnection, Java HttpURLConnectionS, FTP, SFTP, TFTP, Gopher i druge.
Kako pretvoriti CURL u Java HttpURLConnection kod?
Korak 1: Zalijepite i pretvorite svoje CURL zahtjeve u Java HttpURLConnection kod
Korak 2: Kopirajte Java HttpURLConection kod
Primjer pretvaranja CURL u Java HttpURLConnection
KOVRČA
curl example.com
Java HttpURLCection 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);
}
}