IPP Printing返回Unauthorized

时间:2018-06-06 11:37:54

标签: printing laravel-5.6 cups php-7.2

我想从我的网络应用程序打印标签,为此我正在使用这个包。 (https://github.com/smalot/cups-ipp)。我使用包提供的示例代码,当我发送PDF文件打印我得到以下错误:

HTTP \客户端\共同\异常\ ClientErrorException(401) 未经授权的

当我查看我的打印机队列时,我看到状态已中止,文件大小为0KB。我确信文件找到了正确的方法,因为当我进行一些调试时,我可以看到PDF的流正确,但在发送的请求中,我无法找回它。请求如下:

Request {#995 ▼
  -method: "POST"
  -requestTarget: null
  -uri: Uri {#996 ▼
    -scheme: ""
    -userInfo: ""
    -host: ""
    -port: null
    -path: "/"
    -query: ""
    -fragment: ""
  }
  -headers: array:1 [▼
    "Content-Type" => array:1 [▼
      0 => "application/ipp"
    ]
  ]
  -headerNames: array:1 [▼
    "content-type" => "Content-Type"
  ]
  -protocol: "1.1"
  -stream: Stream {#998 ▼
    -stream: stream resource @14 ▼
      wrapper_type: "PHP"
      stream_type: "TEMP"
      mode: "w+b"
      unread_bytes: 0
      seekable: true
      uri: "php://temp"
      options: []
    }
    -size: 140
    -seekable: true
    -readable: true
    -writable: true
    -uri: "php://temp"
    -customMetadata: []
  }
}

我不知道它的价值是否有价值,但我的应用程序是基于laravel 5.6。

执行打印作业的代码:

public function testPrinter() {
    $client = new Client();
    $builder = new Builder();
    $responseParser = new ResponseParser();

    $printerManager = new PrinterManager($builder, $client, $responseParser);
    $printer = $printerManager->findByUri('ipp://localhost:631/printers/OKI_ES7131_D66B77');

    $jobManager = new JobManager($builder, $client, $responseParser);

    $job = new Job();
    $job->setName('job create file');
    $job->setUsername('kasper');
    $job->setCopies(1);
    $job->setPageRanges('1');
    $job->addFile('/var/www/justproduce/public/helloworld.pdf', 'test');
    $job->addAttribute('media', 'A4');
    $job->addAttribute('fit-to-page', true);
    $result = $jobManager->send($printer, $job);
}

1 个答案:

答案 0 :(得分:0)

必须使用凭据初始化新客户端。立即行动。