使用node.js ipp模块的CUPS-Get-Devices上的IPP Missing属性

Jak*_*kub 5 printing cups node.js

我遇到了CUPS-Get-Devices缺少必需属性的问题.基本上我想使用https://www.npmjs.org/package/ipp获取IPP和CUPS的可用打印机列表.

我已经在包中实现了CUPS-Get-Devices,因为它不支持包的属性,但我得到它的工作.问题是响应响应"状态消息":"缺少必需的属性".并没有给我打印机列表.

var uri = "http://localhost:631"
var data = ipp.serialize({
  "operation": "CUPS-Get-Printers",
  "operation-attributes-tag": {
  "attributes-charset": 'utf-8',
  "attributes-natural-language": 'en-us',
  "limit": 10
 }
});

ipp.request(uri, data, function(err, res){
  if(err){
    return console.log(err);
  }
  console.log(JSON.stringify(res,null,2));
});
Run Code Online (Sandbox Code Playgroud)

回应是

{
  "version": "2.0",
  "statusCode": "client-error-bad-request",
  "id": 67392993,
  "operation-attributes-tag": {
    "attributes-charset": "utf-8",
    "attributes-natural-language": "en-us",
    "status-message": "Missing required attributes."
  }
}
Run Code Online (Sandbox Code Playgroud)

文档没有说明其他所需参数http://www.cups.org/documentation.php/spec-ipp.html#CUPS_GET_PRINTERS

有谁知道问题出在哪里?谢谢!

pdw*_*pdw 5

该代码适用于我,使用未修改的 ipp 库和 CUPS 1.7.3。我最好的猜测是您在修改库时犯了拼写错误或其他错误。

var ipp = require('ipp');

// Add missing operation code
ipp.operations['CUPS-Get-Printers'] = 0x4002;

// The rest is identical to your code:

var uri = "http://localhost:631";
var data = ipp.serialize({
  "operation": "CUPS-Get-Printers",
  "operation-attributes-tag": {
    "attributes-charset": 'utf-8',
    "attributes-natural-language": 'en-us',
    "limit": 10
  }
});

ipp.request(uri, data, function(err, res){
  if(err){
    return console.log(err);
  }
  console.log(JSON.stringify(res,null,2));
});
Run Code Online (Sandbox Code Playgroud)