0

次のコードを使用して、 node.js経由でhttp GETリクエストを作成しました

http.get({host:'google.com'},
        function(res){});

しかし、クエリ文字列を含む GET リクエストを作成する方法は次のとおりです: http://myhost/path?query1= "val1"&query2="val2" ???

4

1 に答える 1

0

次のようにパスを追加できます。

var options = {
  host: 'myhost',
  port: 80,
  path: '/path?query1=val1&query2=val2'
};

http.get(options, function(res) {
  console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
  console.log("Got error: " + e.message);
});
于 2012-04-21T19:11:59.187 に答える