Http POST printing and CORS

Anonymous (not verified) -
788
21
profile

Anonymous (not verified)

Please Register or Login to post a reply

21 Replies

Y Yanis Dalabiras

Hi Kai,
The code I posted will work in Chrome and Firefox browsers for most Zebra printers including the GX430t if they are Wi-Fi or Ethernet connected.  It's easier to state which printers it won't work in:
Card printers
Kiosk printers other than KR403 (KR403 works)
ZQ110
EN220 and EN220II
I can't guarantee it will work in discontinued mobile printers or stationary printers discontinued more than 3 years ago. 

R Robert Mosolgo

Hi, just wanted to check the status of this issue.

We want to support Zebra printers for our browser-based product. We won't have any servers -- just clients using their web browsers -- so using an intermediary webserver isn't an option for us.

Do any recent models include the "Access-Control-Allow-Origin" headers to enable CORS? Is it possible to upgrade printers that were already purchased?

I'd love to add support for your hardware. The printers are so good! We just need to satisfy the browser's security requirements!

Thanks,

Robert

Y Yanis Dalabiras

Then the Web-Printing Driver is probably your best option as it does support USB as well as network.

D Darryn Campbell

Hello Robin,

First thank you for this post and the "Http Post Printing" one as well.

I am building an oracle Apex application for our company. We have centers in many countries and they all need to print using Zebra printers as well as normal thermal printers.

For Zebra, and because we have various types of printers, I went with the javascript solution.

first, I came across the CORS issue and since the printer is printing anyways, I ignored the error message.

Then I came across another issue, <strong>Some printers respond to</strong>:
<em><a href="http://">http://</a> + ip_addr + /printer/pstprnt</em>
<strong>And others to</strong>:
<em><a href="http://">http://</a> + ip_addr + /pstprnt</em>
<strong>So in my code I call both and one of them usually respond? do you have another suggestion?</strong>

Second, what about <strong>error handling</strong>? the printer is responding with an error anyways, so how can I tell?
<strong>Is there anyway I can verify the URL before sending the requests?</strong>

<strong>Last, on one of the sites, I can ping the printer, yet when I type the IP in the browser, I can`t open the configuration page -the printer is ZT 230-, do you have any suggestions on how I can trouble shoot that?</strong>

I am not sure what I can and can`t ask you, so please if any of those questions is not in your domain just ignore it, or kindly let me know where should I ask it.

Thanks.

D Darryn Campbell

Hi Robert,
Unfortunately no, we have not updated the printers yet with this fix.&nbsp; We do have some other options though, many of which are outlined in this document: <a href></a>​&nbsp; In your situation I would probably recommend the Web-Printing Driver as the closest fit.&nbsp; If your clients are primarily using the same type of browser, like Chrome or Firefox, there might also be solutions like extensions that should work.

R Robert Mosolgo

Thanks, that document looks like it has some good leads!

After all that, I bought a GK420d <em>without </em>the built-in print server (no ethernet port) so I'll have to try something other than that HTTP endpoint anyways.

Thanks again!

Robert

R Ryan McBee

Robin,

Have any plans been made to resolve this? I'm developing a B2B cloud solution be we're trying to minimize any presence on customer networks. I'd really like to use the HTTP post method, but I'm nervous that future browsers will break this by restricting this type of communication.

Y Yanis Dalabiras

Hi Ryan,
Zebra product management is aware of the issue and evaluating the best course forward. Based on demand from our users we have developed several other ways to handle <a href="/community/technologies/printers/label-printers/blog/2016/02/26/zebra-web-printing-solutions">web based printing</a>​ including the new <a href="/community/technologies/printers/label-printers/blog/2016/08/30/new-developer-tool-released-browser-print">Browser Print</a> tool.&nbsp;&nbsp; We are l<a href="https://www.surveymonkey.com/r/NSTHL2W">ooking for feedback</a> into what use cases our developers are using to influence the prioritization of new tools and features.

J Jan Schinacher

Hi Robin,

is there any update on this? Is there a new firmware for the printers, so the <strong>access-control-origin-header</strong> is set to accept data from any source?

We are working with the javascript solution for 1.5 years now and it is rock solid. We don't have additional software on the devices which trigger the label printing. And we have no problems what so ever.

However, I'm afraid that an automatic update of Google Chrome will break the entire installation.

Thanks for your update on this,

Jan

t testtt test

We apologize for the inconvenience. The Km.zebra.com site is back up now.

M Michael Faircloth

Hey Robin,

Just to confirm, yesterday we were able to print using your HTTP POST demo code from an HTTPS site. There have been a few issues with having to confirm the generated certificate from the client side, but it does print from HTTPS.

Hopefully this can help others in a similar situation.

M Michael Faircloth

Hello, it appears the HTTPS might be supported now if you put an SSL certificate on the printer.

Programming Guide – Page 768 – ZQ520 has HTTPS capability
<a href="https://www.zebra.com/content/dam/zebra/manuals/en-us/software/zpl-zbi2…;

Administration Guide -&nbsp; Page 10, Page 48-50 – How to generate SSL certificate and place on printer
<a href="https://www.zebra.com/content/dam/zebra/utilities/en/configuration/prin…;

You can go check your variables to see if you have ip.https.enable. If your printer is supported and you don't you may just need to download the lastest firmware.

Y Yanis Dalabiras

Thanks Michael for pointing this out.&nbsp; I'll verify this use case.&nbsp; I do know the user supplied SSL cert functionality is new in Link-OS firmware.&nbsp; I'll post the firmware version version that it was implemented in.

T Thomas McCobb

I think browser updates are wreaking havoc.&nbsp; This worked initially (a few months ago).

In our test environment we can print successfully from Firefox but not Chrome.&nbsp; At a customer site that is a Mac environment, they cannot print from either.&nbsp; The web pages are served up externally, so there might be a CORS issue.&nbsp; I tried the CORS anywhere plugin for Firefox, but that has not helped.

But I cannot even get a response in the Mac environment. I can see the Browser Print listening on ports 9101 and 9100.&nbsp; In a browser console, I can see the call to GET <a href="https://localhost:9101/default">https://localhost:9101/default</a&gt;, and it shows the request headers, but the response headers are never returned.&nbsp; I am guessing that Firefox is blocking the response altogether, but I cannot see why.&nbsp; Can you point me in the right direction?

BTW, I was trying to download the Mac version of Browser Print again today, but the download page links to something different.

A Albino Noynay

Hi <a href></a>​,

I'm trying to use the zebra browser print and tried to integrate the code found in ZebraBrowserPrintDocsWebCodeExamples but I received an error "Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at <a href="https://localhost:9101/default?type=printer">https://localhost:9101/def…;. (Reason: CORS request did not succeed)."

I'm developing Salesforce visualforce page using the following
1. Firefox, Edge, Chrome browser
2. Windows OS (Laptop)
3. Zebra GK420t printer

Thanks,
Albino

R Robin West

Hello,

I have same problems + https problem :
- CORS browser rejects a direct call
- call HTTP over HTTPS is not allowed

Solution i have implemented/tested :

1. use an intermediate server : often you are adding a "print" button in your web interface. You can call the printer via this server. Server side script does not checks CORS at all.One problem is if your web server cannot contact your printer due to network segregation (printer in 192.168.x.x, server in the internet, and no way to communicate between them)

2. use web browser : latest fetch API allows for 'no-cors' request mode. This means no address checkup done for this request.
web api support : <a href="https://developer.mozilla.org/en/docs/Web/API/Fetch_API">Fetch API - Web APIs | MDN</a>
It works, but Fetch api is not available in IE (if someone still use it).
This solution is&nbsp; not 'perfect' but works if you have network segregation (printer cannot be contacted by server) and your client know printer IP.

var request = new Request('<a href="http://192.168.2.2/printer/pstprnt">http://192.168.2.2/printer/pstprnt<…;,
&nbsp; {
&nbsp;&nbsp; method: 'POST',
&nbsp;&nbsp; mode: 'no-cors',
&nbsp;&nbsp; cache: 'no-cache',
&nbsp;&nbsp; body: 'ZPL CODE'&nbsp; });
fetch(request)
&nbsp; .then(function (response) {
&nbsp;&nbsp; // Important : in 'no-cors' mode you are allowed to make a request but not to get a response&nbsp; // even if in 'Network' Tab in chrome you can actually see printer response&nbsp; // response.ok will always be FALSE and response.text() null&nbsp; /*if (!response.ok) {&nbsp; throw Error(response.statusText);&nbsp; }*/&nbsp;&nbsp; return true;
&nbsp; })
&nbsp; .catch(function (error) {
&nbsp;&nbsp; // note : if printer address is wrong or printer not available, you will get a "Failed to fetch"&nbsp;&nbsp; console.log(error);
&nbsp; });

3. HTTPS :
Currently printer is using only HTTP, since your website should be protected by default your client use HTTPS instead of HTTP.
You can use solution 1 if same network.
But if you are in network segregation you want to use solution 2. Problem : browser will not allow request to HTTP in an HTTPS website (<a href="https://developers.google.com/web/fundamentals/security/prevent-mixed-c… Mixed Content&nbsp; |&nbsp; Web&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp; Google Developers</a>&nbsp; ) : So in this last case there is no solution simple at the moment !
a solution could be : add a Raspberry pi (or whatever local server) to bridge printer in https.

It would be nice if Zebra printer could implement an HTTPS server, it means give the possibility to provide an url and a certificate.

Hope this help.

K Kai Song

I have one question for the POST printing function:
Are all Zebra printer which has the wireless LAN enabled is qualified for the POST printing function?
Will the code you posted for the POST sample be working for all printers?
We recently get one GX430t but realized there is no wireless LAN in it, so we gonna get a new one with wireless enabled. Need some advice before we actually make the purchase.

Thanks

N Nick van de Luijtgaarden

Hi Robin,

Does the Browser Print tool use HTTP POST, just like your other post (see: <a href></a> )? I am struggling to get Zebra printing working on a HTTPS server.

Thanks!

Y YoungMi Kim

Hi Robin,

Thank you for your detailed explanation.
Our company uses the ZT410 model.
I'm sorry, but I do not know what to do if I read the explanation above.
Let me explain how we would like to use it.
1. SERVER (Not in the same network, not in our company, in another area.)
2. User PC
3. ZT410 connected to your PC
4. Router
SERVER - Router - User PC - Consists of ZT410 connected to user PC.
I want to print ZPL with ZT410 through CHROME browser connected to SERVER. The languages ​​we use are JAVA and JSP. TOMCAT and DATABASE are installed in SERVER.
When testing, install TOMCAT, JAVA, JSP on the user's PC, connect only DATABASE to the SERVER, and print the ZT410 connected to the user's PC.
However, the actual usage environment should be connected to the program of SERVER.
Please help me print this.
If there is a method or a sample source, it is better.
You will be busy too. I'm sorry, but I would appreciate it if you answer. ^^
I have tried for a long time, but it is too difficult because I have no achievements.
Please help me ..

(If English is strange, please understand.)

e-mail : <a href="mailto:mdis@mdis.co.kr">mdis@mdis.co.kr</a&gt;

s shaoxiong wang

Dear Robin,

WE can not access <a href="/community/technologies/printers/label-printers/blog/2016/02/26/zebra-web-printing-solutions">Zebra Web Printing Solutions.</a>

G Glenn Meader

There is a very simple change that Zebra could make in the firmware to deal with the CORS issue being discussed here.
Your document: HTTP Post AppNote 2456949.667535 of October 19, 2014 on page 4 describes the response the printer gives
after receiving the POST request. It always responds with a fixed string.
HTTP/1.1 200 OK
Content-Type: text/html
Expires: Sat, 01 Jan 2000 00:00:00 GMT
All Zebra needs to do to fix the problem is append the following line to to this fixed string:
Access-Control-Allow-Origin: *