007 nodejs服務端api接口內請求另一api接口

  • 方法一:

  • 目標接口地址

https://api.q.qq.com/sns/jscode2session?appid=' + qq.APPID + '&secret=' + qq.APPSECRET + '&js_code=' + req.query.code + '&grant_type=authorization_code
  • 請求實現

// QQ小程序配置信息
const qq = require('../config/Config')

router.get('/onLogin', function (req, res) {
  const url = 'https://api.q.qq.com/sns/jscode2session?appid=' + qq.APPID + '&secret=' + qq.APPSECRET + '&js_code=' + req.query.code + '&grant_type=authorization_code'
  request.get(url, function (req,resp, res) {
    console.log(res)
  })

方法二:推薦

npm install -g xd-synchttp
const sync = require('xd-synchttp');

let content = "";
const url = 'www.baidu.com';
try{
    content = sync.http_get(url,0);
    //0爲不超時,其他數值爲超時秒數
}
catch(err)
{
    console.log(err);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章