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
    }
  }
原文地址:https://www.cnblogs.com/vipzhou/p/6769134.html