Has anyone started having issues with HTTP post printing lately?


Audience
Tags

Have had a web application successfully using http post method of printing to our Zebra 230's for years now, but just recently started having issues. It seems any PC cannot print, but our android devices can. I'm guessing it is most likely due to browser issues, (perhaps after updates??). Have tried multiple browsers on the PC (chrome, ie, ff) though and none are working. Can successfully print to the printer through Zebradesigner from same PCs, so know it's not a network/connection issue.

Anyone else noticing this?

Submitted by SSi1 on October 27, 2021 Permalink

Do you see any specific error messages? Chrome debug mode can help to see what exact error is from the pstprnt request. The pstprnt may not have been kept up to date with the latest versions of the browsers. 

Submitted by alex@ssstave.com on October 27, 2021 Permalink

There are no thrown errors.

I checked in chrome debugger and only noticed a flag on the line -
request.setRequestHeader("Content-Length", zpl.length); *Refused to set unsafe header "Content-length"

Researched and found that it shouldn't be necessary to set content-length, so tried commenting out that line.
Still not working from any PC on the network or from any browser (chrome, ie, ff) but works just fine from any android or ios device using chrome or safari.

I am not extremely familiar with chrome debugger, let me know if there is something further I can explore with it, thanks for the input!

Submitted by SSi1 on October 27, 2021 Permalink

In general, browsers for desktop or PC are different from the browsers for mobile devices. A POST request for pstprnt is as simple as shown below. 

curl -X POST http://192.168.1.100/pstprnt \
     -d "^XA^FO50,50^ADN,36,20^FDHello World-XFS^XZ"

Can you share the code around the pstprnt, so we can see what's been put into the request?

Submitted by alex@ssstave.com on November 01, 2021 Permalink

I have not tried using curl but can give it a try. We have been using the provided javascript: 

        var zpl = document.getElementById("zpl").value;
        var url = "http://<?php echo $printerIP; ?>/pstprnt";
        var method = "POST";
        var async = true;
        var request = new XMLHttpRequest();
        
        request.open(method, url, async);
        request.setRequestHeader("Content-Length", zpl.length);
 
        // Actually sends the request to the server.
        request.send(zpl);

 

Submitted by SSi1 on November 01, 2021 Permalink

Please comment out the Content-Length header and try again. The pstprnt does not use the Content-Length header.

var zpl = document.getElementById("zpl").value;
var url = "http://<?php echo $printerIP; ?>/pstprnt";
var method = "POST";
var async = true;
var request = new XMLHttpRequest();

request.open(method, url, async);
// request.setRequestHeader("Content-Length", zpl.length);

// Actually sends the request to the server.
request.send(zpl);

 

Submitted by alex@ssstave.com on November 24, 2021 Permalink

I finally came back to this issue, sorry have been away. I have resolved the issue and the script you provided helped.
I had found that my script was throwing CORS errors due to 'origin' and assumed it was the issue. Although identical, I ran your provided script and it too threw the same errors....but it actually printed! Only difference was it's origin was 'null'. This lead me to digging in a more precise area and found this:
"August 25, 2021: Chrome is deprecating access to private network endpoints from non-secure websites as part of the Private Network Access specification. "

https://developer.chrome.com/blog/private-network-access-update/

.... which is when we started having issues. The whole fix....have to call it from within the same CORS origin -OR- have a valid SSL cert and must call via https. Thanks for the assistance!