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);
curl --help | lessand the/timeand there are numerous othertimeoptions, 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!