javascript - 我可以在 Node.js 中使用 PaperCut (XML-RPC) API 吗?
问题描述
我打算使用 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 中使用一段代码从 Node.js 请求它吗?
解决方案
我在剪纸软件工作
抱歉,我花了这么长时间才回复这个问题,但我最终找到了一个空闲的下午来敲一些代码。
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
推荐阅读
- jquery - 为什么这个 jQuery 调用在 Firefox 中失败?
- php - Google Calendar API 为每个服务调用返回 500 错误代码
- css - 如何在 chartist.js 中为图表背景着色
- ruby - 有没有办法删除 Ifs 并改用函数
- angular - 如何为 Google Cloud Firestore 添加和检索智能表数据
- amazon-web-services - 每次启动 AWS EC2 实例时为其分配一个 DNS
- sql-server - SQLAlchemy 和 mssql:如何创建具有多个空值的唯一约束
- python - 无法运行 AWS CLI:ImportError: cannot import name 'HTTPClientError'
- python - 如何保护 PyPI 包不被删除
- javascript - 将选中的属性赋予循环内的单选按钮