通过php连接到ipp

发布于 2025-01-10 08:39:26 字数 1874 浏览 2 评论 0原文

我怎样才能连接到 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);

我找到了这些库,但对我来说没有用

我想了解 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

I want to learn how ipp protocol works and to connect it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文