SORU
6 AĞUSTOS 2011, CUMARTESİ


Nerede nodejs bir http organıdır.yanıt mı?

http://nodejs.org/docs/v0.4.0/api/http.html#http.request ama nedense, aslında vücudun bul/data döndürülen için öznitelik, yanıt bitmiş nesne gibi görünmüyorum at belgeleri okuyorum.

coffee> res = http.get({host:'www.somesite.com',path:'/'})

coffee> res.finished
true

coffee> res._hasBody
true

(Http.bitti bunu sizin için yapar), yani içerik bir tür olmalıdır. Ama ceset yok, Veri yok, okuyamıyorum. Vücut saklanıyor?

CEVAP
6 AĞUSTOS 2011, CUMARTESİ


9* *docs data olay yönetimi: yanıt vücut almak için nasıl bir örnek içerir

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();

http.get http olarak aynı şeyi yapar.req.end() otomatik olarak çağırır dışında istek.

var options = {
  host: 'www.google.com',
  port: 80,
  path: '/index.html'
};

http.get(options, function(res) {
  console.log("Got response: "   res.statusCode);

  res.on("data", function(chunk) {
    console.log("BODY: "   chunk);
  });
}).on('error', function(e) {
  console.log("Got error: "   e.message);
});

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

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • DancingIsAPassion

    DancingIsAPa

    29 AĞUSTOS 2009
  • sdasmarchives

    sdasmarchive

    2 HAZİRAN 2010
  • xiaoyu85

    xiaoyu85

    20 ŞUBAT 2010