SORU
25 Temmuz 2011, PAZARTESİ


Nodejs eşdeğer Curl?

Bir HTTP isteği nodejs (yani uzak bir web servisi arayın ve istemciye yanıt echo) kullanarak bilgi kullanmak için arıyorum.

PHP curl bunu yapmak için kullanırdım. Düğüm en iyi uygulama nedir?

CEVAP
25 Temmuz 2011, PAZARTESİ


Sunucuları çalıştırmak için kullandığınız http Bu modül de uzak istekleri yapmak için kullanılır.

İşte onların docs: örnek

var http = require("http");

var options = {
  host: 'www.google.com',
  port: 80,
  path: '/upload',
  method: 'POST'
};

var req = http.request(options, function(res) {
  console.log('STATUS: '   res.statusCode);
  console.log('HEADERS: '   JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: '   chunk);
  });
});

req.on('error', function(e) {
  console.log('problem with request: '   e.message);
});

// write data to request body
req.write('data\n');
req.write('data\n');
req.end();

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • My name is Festis and I'm free

    My name is F

    2 EKİM 2011
  • max2sims2

    max2sims2

    19 Kasım 2008
  • TrenchTech Computer Repair Tutorials

    TrenchTech C

    19 EYLÜL 2014