request发送json-rpc请求

直接贴代码吧:

let url = '/rest/2.0/res/auth_token?session=' + session
  url += getUrlTokenQuery()
  const method = 'Stream.open'
  const params = { // 预览参数
    'channel': 1,
    'ip': 0,
    'protocol': 1,
    'port': 0,
    'coder': 0
  }
  var requestData = {
    jsonrpc: '2.0',
    id: ++id,
    method: 'brest',
    params: {
      call: method,
      args: params
    }
  }
  const options = {
    method: 'post',
    uri: `${ip}:${port}${url}`,
    body: requestData,
    json: true
  }
  try {
    const result = await rp(options)
    return {
      result: result,
      err: ''
    }
  } catch (err) {
    return {
      result: null,
      err: err
    }
  }

 

posted @ 2017-04-26 16:11  程序员小波与Bug  阅读(1475)  评论(2编辑  收藏  举报