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

  • BigDawsVlogs

    BigDawsVlogs

    17 HAZİRAN 2013
  • Lancome USA

    Lancome USA

    30 HAZİRAN 2009
  • Videogamerz | Call of Duty

    Videogamerz

    5 NİSAN 2012