通过php连接到ipp
我怎样才能连接到 ipp 服务器并在没有任何库的情况下找到工作?我在 ubuntu 18 上安装了 cups 2.2。 我尝试过这段代码但不起作用。
$host = "server-ip";
$path = "/jobs";
$fp = fsockopen($host, 631, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$username = "user";
$password = "secret";
$pass = base64_encode($username . ":" . $password);
$dataString = "";
$dataString .= chr(0x01) . chr(0x01) // 1.1 | version-number
. chr(0x00) . chr(0x0A) // Get-Jobs | operation-id
. 1 // request-id
. chr(0x01) // start operation-attributes | operation-attributes-tag
. "utf-8" //charset
. "en-US" //language
. "https://server-ip/printers/Virtual_Printer" //printer_uri
. $username
. 0 //limit
. "not-completed" //which_jobs
. false; //my_jobs
$string = sprintf("POST %s HTTP/1.1\r\n", "/jobs");
$string .= sprintf("%s: %s\r\n", "User-Agent", "PRINTIPP/0.81+CVS");
$string .= sprintf("%s: %s\r\n", "Host", $host);
$string .= sprintf("%s: %s\r\n", "Content-length", strlen($dataString));
$string .= sprintf("%s: %s\r\n", "Content-type", "application/ipp");
$string .= sprintf("%s: %s\r\n", "Authorization", "Basic ".$pass);
$string .= sprintf("%s: %s\r\n", "Data", $dataString);
$string .= "\r\n";
fwrite($fp, $string);
while (!feof($fp)) {
echo fgets($fp, 1024);
}
}
fclose($fp);
我找到了这些库,但对我来说没有用
- https://github.com/nateobray/IPP
- https://github.com/smalot/cups-ipp
- http://www.nongnu.org/phpprintipp/
我想了解 ipp 协议的工作原理并进行连接它。
How can i connect to ipp server and get jobs without any library? I installed cups 2.2 on ubuntu 18.
I'm tried this code but not working.
$host = "server-ip";
$path = "/jobs";
$fp = fsockopen($host, 631, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$username = "user";
$password = "secret";
$pass = base64_encode($username . ":" . $password);
$dataString = "";
$dataString .= chr(0x01) . chr(0x01) // 1.1 | version-number
. chr(0x00) . chr(0x0A) // Get-Jobs | operation-id
. 1 // request-id
. chr(0x01) // start operation-attributes | operation-attributes-tag
. "utf-8" //charset
. "en-US" //language
. "https://server-ip/printers/Virtual_Printer" //printer_uri
. $username
. 0 //limit
. "not-completed" //which_jobs
. false; //my_jobs
$string = sprintf("POST %s HTTP/1.1\r\n", "/jobs");
$string .= sprintf("%s: %s\r\n", "User-Agent", "PRINTIPP/0.81+CVS");
$string .= sprintf("%s: %s\r\n", "Host", $host);
$string .= sprintf("%s: %s\r\n", "Content-length", strlen($dataString));
$string .= sprintf("%s: %s\r\n", "Content-type", "application/ipp");
$string .= sprintf("%s: %s\r\n", "Authorization", "Basic ".$pass);
$string .= sprintf("%s: %s\r\n", "Data", $dataString);
$string .= "\r\n";
fwrite($fp, $string);
while (!feof($fp)) {
echo fgets($fp, 1024);
}
}
fclose($fp);
I found these libraries but not usefull for me
- https://github.com/nateobray/IPP
- https://github.com/smalot/cups-ipp
- http://www.nongnu.org/phpprintipp/
I want to learn how ipp protocol works and to connect it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论