1

I try curl on a host that it is a cash register printer. The printer can accept instructions via http in the body of the request, like this example:

[www@localhost ~]$ curl --trace curl.trace.log -d '
> clear
> vend rep=1, pre=10
> vend rep=2, pre=20
> chius
> wecfine
>' http://192.168.6.184:1471

But I can't understand why launching this command the destination host responds correctly to the instructions in the body and the printer work correctly but after the log response the connection is kept open for 30 seconds and after this time curl responds in this way: Connection #0 to host 192.168.6.184 left intact. My problem is that I tried to log response headers in all the ways (--trace curl.trace.log, --trace-ascii curl.trace-ascii.log, --dump-header curl.dump-header.log and the last -v) but none of these works. The only response log that I have with all the ways is this:

* About to connect() to 192.168.6.184 port 1471 (#0)
*   Trying 192.168.6.184...
* Connected to 192.168.6.184 (192.168.6.184) port 1471 (#0)
> POST / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.6.184:1471
> Accept: */*
> Content-Length: 57
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 57 out of 57 bytes
OK.
OK.
OK.
OK.
OK.
* Connection #0 to host 192.168.6.184 left intact

Question

Why don't I get headers in the response despite using the verbose? I need to understand how the printer work and with headers I can get more information becouse I have to develop calls from a web application to this device.

Other information

For curl calls to the printer I will use php.

This cash register has a really poor and incomplete documentation.

[Edit]

The curl command in PHP that is for test, the result is the same, the variable $headers is just an empty array!

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://192.168.6.184:1471');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '
clear
vend rep=1, pre=10
vend rep=2, pre=20
chius
wecfine
');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: text/plain']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$headers = [];
curl_setopt($ch, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$headers)
{
    $len = strlen($header);
    $header = explode(':', $header, 2);
    if (count($header) < 2) // ignore invalid headers
        return $len;

    $headers[strtolower(trim($header[0]))][] = trim($header[1]);

    return $len;
    }
);

$output=curl_exec($ch);
curl_close($ch);
1
  • 1
    Not clear if you wish the connection would terminate completely. Would ` -m, --max-time SECONDS ` help? I did curl --help | less and the /time and there are numerous other time options, each more obscure than the previous ;-), but maybe one of them might help you. You'll get more readers for your Q if you include a tag for the programming language you are using for your project. Good luck! Commented Dec 12, 2019 at 15:33

1 Answer 1

1

Without knowing anything about receipt printers, my guess based solely on the instructions you are sending is that it may be a dumb terminal, meaning it will accept input and print things, but does not provide any sort of information BACK to the requestor. If it is indeed set up this way, the "web server" you're interacting with may be VERY rudimentary and only be set up to receive connections.

You may need to just send commands to the printer and hope it does what it's supposed to.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.