美文网首页
Node.js中request的用法

Node.js中request的用法

作者: 鹿鹿小讲堂 | 来源:发表于2015-11-30 13:53 被阅读432次

发送 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的用法

      本文链接:https://www.haomeiwen.com/subject/xarjhttx.html