Has anyone started having issues with HTTP post printing lately?

// Expert user has replied.
A Alex Skinner 3 years ago
537 9 0

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?

Please Register or Login to post a reply

9 Replies

S Steven Si

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. 

A Alex Skinner

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!

S Steven Si

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?

A Alex Skinner

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);

 

S Steven Si

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);

 

A Alex Skinner

I had read that too and tried with it commented out as well (noted in the post above) and it didn't make a difference, it still only worked with mobile browsers and no PC browser.

S Steven Si

Not sure what else could cause the failure in your case without additional exception trace or error msg. This HTTP Post example of pstprnt works just fine for me with Chrome on Mac and Windows. You can copy the link and paste it into the address box to download the zip file.

A Alex Skinner

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!

M Marek Klimczuk

Nice, thank you very much!

__________________________

Blog

CONTACT
Can’t find what you’re looking for?