サーバーhttpリスナーを作成しました:
var http = require('http');
http.createServer(function (req, res)
{
res.writeHead(200,
{
'Content-Type': 'text/plain'
});
res.write('aaa');
res.end();
}).listen(1337, '127.0.0.1');
console.log('waiting......');
それは、検索と応答を実行しています。
今、私は欲しいです-foreachクライアントリクエスト-サーバーは別のリクエストを実行し、文字列を追加"XXX"
します :
だから私は書いた:
var http = require('http');
var options = {
host: 'www.random.org',
path: '/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
};
http.createServer(function (req, res)
{
res.writeHead(200,
{
'Content-Type': 'text/plain'
});
res.write('aaa');
http.request(options, function (r)
{
r.on('data', function (chunk)
{
res.write('XXX');
});
r.on('end', function ()
{
console.log(str);
});
res.end();
});
res.end();
}).listen(1337, '127.0.0.1');
console.log('waiting......');
したがって、foreachリクエストでは、次のように記述します:aaaXXX
(aaa + XXX)
しかし、それは機能しません。それでも同じ出力を生成しました。
私は何が間違っているのですか?