Node.js中request的用法

发送 JSON 参数

var request = require('request');

var options = { 
  uri: 'https://www.googleapis.com/urlshortener/v1/url', 
  method: 'POST', 
  json: { "longUrl": "http://www.google.com/" }
};

request(options, function (error, response, body) { 
  if (!error && response.statusCode == 200) { 
    console.log(body.id) // Print the shortened url.
  }
});

GET 方法

request.get(url, function(error, response, body) {
  console.log(JSON.parse(body));
});

你可能感兴趣的:(Node.js中request的用法)