nodejs request CURl 抓取网页数据

Node 利用request获取API、网页数据

本例用于通过微信授权回调code获取UserInfo信息

let request = require('request');
let requestData = '';
let url = `https://api.weixin.qq.com/sns/oauth2/access_token?appid=${config.wx.appid}&secret=${config.wx.secret}&code=${code}&grant_type=authorization_code`;

responsebody = request({
  url: url,
  method: "GET",
  json: true,
  headers: {
    "content-type": "application/json",
  },
  body: JSON.stringify(requestData)
}, function(error, response, body) {
  if (!error && response.statusCode == 200) {
  return body
  }
});

你可能感兴趣的:(nodejs request CURl 抓取网页数据)