Pretvorite ukaze CURL v kodo Java HttpURLConnection na spletu

Curl command

Examples: GET - POST - JSON - Basic Auth - Files - Form

CURL v Java HttpURLConection Online

To orodje vam pomaga ustvariti kodo Java HttpURLConection na podlagi ukaza CURL. Kopirajte in prilepite ukaz CURL ter ustvarite Java HttpURLConnection.

Kaj lahko storite s spletnim pretvornikom CURL v Java HttpURLConnection?

  • CURL v Java HttpURLConnection je zelo edinstveno orodje za pretvorbo ukaza cURL v zahtevo Java HttpURLConnection Java HttpURLConnection. Vnos, ki ga uporabnik zagotovi z ukazom cURL za ustvarjanje Java HttpURLConnection kode.
  • To orodje prihrani vaš čas in pomaga z lahkoto ustvariti kodo Java HttpURLConnection.
  • CURL to Java HttpURLConection dobro deluje v sistemih Windows, MAC, Linux, Chrome, Firefox, Edge in Safari.

kaj je CURL?

cURL je odprtokodno orodje ukazne vrstice, ki prenaša datoteke iz spleta. Podpira različne protokole, vključno z Java HttpURLConnection, Java HttpURLConnectionS, FTP, SFTP, TFTP, Gopher in drugimi.

Kako pretvoriti CURL v Java HttpURLConnection kodo? 

1. korak: Prilepite in pretvorite svoje zahteve CURL v kodo Java HttpURLConnection

2. korak: Kopirajte kodo Java HttpURLConection

Primer pretvorbe CURL v Java HttpURLConection

CURL
curl example.com
Java HttpURLConection 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);
    }
}