Badilisha amri za CURL kuwa msimbo wa uunganisho wa Java HttpURL mtandaoni

Curl command

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

CURL kwa Java HttpURLConnection Online

Zana hii hukusaidia kutoa msimbo wa muunganisho wa Java HttpURL kulingana na Amri ya CURL. Nakili na Ubandike Amri ya CURL na Unda muunganisho wa Java HttpURL.

Unaweza kufanya nini kwenye CURL hadi Java HttpURLConnection Converter Online?

  • CURL hadi Java HttpURLConnection ni zana ya thamani sana ya kubadilisha amri ya cURL kuwa Java HttpURLOmbi la muunganisho la Java HttpURLConnection. Ingizo muhimu kwa amri ya cURL ya kutengeneza Msimbo wa Muunganisho wa Java HttpURL.
  • Zana hii huokoa muda wako na kusaidia kutoa msimbo wa muunganisho wa Java HttpURL kwa urahisi.
  • CURL kwa Java HttpURLConnection kazi vizuri kwenye Windows, MAC, Linux, Chrome, Firefox, Edge na Safari.

CURL ni nini?

cURL ni mstari wa mstari wa amri ya chanzo-wazi ambayo hupakua kutoka kwa wavuti. Inaauni itifaki mbalimbali, ikiwa ni pamoja na Java HttpURLConnection, Java HttpURLConnectionS, FTP, SFTP, TFTP, Gopher na nyinginezo.

Jinsi ya kubadilisha CURL kuwa nambari ya uunganisho wa Java HttpURL? 

Hatua ya 1: Bandika na ubadilishe maombi yako ya CURL kuwa msimbo wa muunganisho wa Java HttpURL.

Hatua ya 2: Nakili msimbo wa muunganisho wa Java HttpURL

Badilisha CURL kuwa mfano wa Java HttpURLConnection

CURL
curl example.com
Msimbo wa Muunganisho wa Java HttpURL
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);
    }
}