【问题标题】:Can I use the PaperCut (XML-RPC) API in Node.js?我可以在 Node.js 中使用 PaperCut (XML-RPC) API 吗?
【发布时间】:2020-09-20 19:58:34
【问题描述】:

我打算使用 PaperCut API,但据我所知 XML-RPC 不支持 Node.JS 或者我找不到合适的客户端。这是 PaperCut API 的链接: https://www.papercut.com/support/resources/manuals/ng-mf/common/topics/tools-web-services.html

我想知道谁能让它在 JavaScript 中运行。我在 QNAP 中使用 Node.js(在 Container Station 中)。如果它可以在 Python 中运行,我应该安装 Python 容器吗?我可以在 Python 中使用 sn-p 代码从 Node.js 请求它吗?

【问题讨论】:

  • 不要将标签放在问题的标题中。写一个合适的标题。想象一下,您正在向同事提出这个问题。你会问他们“PAPERCUT API | XML-RPC | NODE.JS?”
  • 我试图总结一下我认为标题中的问题。
  • 关于这个问题,我假设 XML-RPC 是否“支持”节点的问题是不合理的 - XML-RPC 是 XML,因此可以用于任何可以阅读的语言/写 XML。
  • 您提供的链接表明支持 Python,但如果您更愿意使用 JavaScript/Node,我确信 XML-RPC 库可用于该语言。 There are several herethis is the first one
  • 貌似也是一些npm剪纸包

标签: javascript node.js api xml-rpc papercut


【解决方案1】:

我在 PaperCut Software 工作

抱歉,我花了这么长时间才回复这个问题,但我最终找到了一个空闲的下午来敲一些代码。

var xmlrpc = require('xmlrpc')

const authToken = 'token'

const hostAddress = "172.24.96.1"
 
// Waits briefly to give the XML-RPC server time to start up and start
// listening
setTimeout(function () {
  // Creates an XML-RPC client. Passes the host information on where to
  // make the XML-RPC calls.
  var client = xmlrpc.createClient({ host: hostAddress, port: 9191, path: '/rpc/api/xmlrpc'})
 
  // Sends a method call to the PaperCut MF/NG server

  client.methodCall(`api.${process.argv[2]}`, [authToken].concat(process.argv.slice(3)), function (error, value) {
    // Results of the method response
    if (undefined === error || null === error) {
        console.log(`Method response for \'${process.argv[2]}\': ${value}`)
    }
    else
    {
        console.log(`Error response for \'${process.argv[2]}\': ${error}`)
    }
  })
 
}, 1000)

要从命令行运行它,请尝试类似

node main.js getUserProperty alec balance

【讨论】:

    猜你喜欢
    • 2013-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2014-09-10
    相关资源
    最近更新 更多