首页 > 解决方案 > 为了获取其属性等,要发布到打印机的 IPP 消息是什么?

问题描述

我正在努力stm32并尝试通过 TCP 获取打印机属性,我正在阅读 IPP 文档并找到要发送的正确消息

创建客户端 TCP 套接字并连接到我的打印机地址的端口 631 然后发送一条带有 Ipp 标头的消息,我从除 HP 打印机之外的所有设备中得到响应,但根据 IPP 文档,响应与预期不符

在 CI 发送

    /ipp HTTP/1.1\r\nContent-Type: application/ipp\r\n
    User-Agent: Internet Printing Provider\r\n
    Host: 10.34.18.44:631\r\nContent-Length: 117\r\n
    Connection: Keep-Alive\r\nCache-Control: no-cache\r\n\r\n
    \001\001\0\v\0\0\0\v
    \001G\0\022attributes-charset\0\005utf-8H\0
    \eattributes-natural-language\0\005en-usE\0
    \vprinter-uri\0\032http://10.34.18.44:631/ipp\003\020

在 C# 中我发送

    string _uri = "10.34.18.44";
    string printeruriValue = _uri + ":631/ipp";
    string content = $"{0x0101}";
    content += $"{0x000A}";
    content += $"{0x00000123}";
    content += $"{0x01}"; 
    content += $"{0x47}{0x0012}attributes-charset{0x0005}utf-8";
    content += $"{0x48}{0x001B}attributes-natural-language{0x0005}en-us";
    content += $"{0x45}{0x000B}printer-uri{0x001A}{printeruriValue}";
    content += $"{0x21}{0x0005}limit{0x0004}{0x00000032}";
    content += $"{0x44}{0x0014}requested-attributes{0x0006}job-id";
    content += $"{0x44}{0x0000}{0x0008}job-name";
    content += $"{0x44}{0x0000}{0x000F}document-format";
    content += $"{0x0003}";

    string message = $"POST {_uri + "/ipp"}  HTTP/1.1\r\n" +
    "Content-Type: application/ipp\r\n" +
    "User-Agent: Internet Printing Provider\r\n" +
    "Host:" + _uri + ":631\r\n" +
    $"Content-Length: {content.Length}\r\n"+
    "Connection: Keep - Alive\r\n" +
    "Cache-Control: no-cache\r\n\r\n"+
    content;

每次我从非 HP 打印机收到

    ReceiveCallback close : HTTP/1.1 200 OK
    MIME-Version: 1.0
    Server: JC-SHTTPD/1.17.23
    Connection: close
    Content-Type: application/ipp
    Content-Length: 33
    Accept-Ranges: none

    ????G?attributes-charset??

从 HP 打印机出现 405 错误,命令未知

标签: printingtcpprotocolsprinters

解决方案


推荐阅读