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

  • Fullscreen

    Fullscreen

    23 Mart 2006
  • PorterRobinsonVEVO

    PorterRobins

    11 Kasım 2013
  • Xcode programming tutorials

    Xcode progra

    17 EYLÜL 2006