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

  • Derek Banas

    Derek Banas

    12 AĞUSTOS 2008
  • SerienTrailerMP

    SerienTraile

    7 HAZİRAN 2012
  • Tech4Geeks

    Tech4Geeks

    8 Ocak 2012