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 回答