“cara menjalankan curl di javascript” Kode Jawaban

cara menjalankan curl di javascript

#Since javascript already has functions for this purpose
#so it is not advisable to load an extra library for that
#you can achieve the same in native javascript like this
var url = "http://www.google.com";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();

#But still if you want to do it using curl in Node.js, it is possible
#Take a look at: https://github.com/JCMais/node-libcurl
var Curl = require( 'node-libcurl' ).Curl;

var curl = new Curl();

curl.setOpt( 'URL', 'http://www.google.com' );
curl.setOpt( 'FOLLOWLOCATION', true );

curl.on( 'end', function( statusCode, body, headers ) {

    console.info( statusCode );
    console.info( '---' );
    console.info( body.length );
    console.info( '---' );
    console.info( this.getInfo( 'TOTAL_TIME' ) );

    this.close();
});

curl.on( 'error', function ( err, errCode ) {

    //do something

    this.close();
});

curl.perform();

Ahmed

cara mengakses data keriting di javascript

var url = "www.yahoo.com";

var xhr = new XMLHttpRequest();
xhr.open("GET", url);

xhr.onreadystatechange = function () {
   if (xhr.readyState === 4) {
      console.log(xhr.status);
      console.log(xhr.responseText);
   }};

xhr.send();
Anthony Smith

Jawaban yang mirip dengan “cara menjalankan curl di javascript”

Pertanyaan yang mirip dengan “cara menjalankan curl di javascript”

Lebih banyak jawaban terkait untuk “cara menjalankan curl di javascript” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya