Mobile App use to send data to print by network printer

Mobile App use to send data to print by network printer

  

Hi everyone,

I'm developing some mobile app for my company and we are using a Samsung Tablet to send some work to a thermal printer that is conected in network, so we use some JS code to send the data, when i make some tests in other device it work perfectly fine (running Andriod too), but when i install the APK on the tablet just stop working, i dont know if it's some kind of restricction in comunication or something else (the printer and the device are both in the same network, talking about IP and that kind of information), can someone guide me about this topic.

Thanks everyone.

Best regards.

Hello Frederick.

What do you mean with "stop working"? The app crashes on start? Are you using any plugin?

Thanks

César Afonso wrote:

Hello Frederick.

What do you mean with "stop working"? The app crashes on start? Are you using any plugin?

Thanks

Hi César, sorry if i wasn't clear before, i mean the JS code stop sending data to the thermal printer, the app works perfectly fine. This is the code i'm using for send the data.

      var url = "http://"+$parameters.ip_addr+"/pstprnt";
      var method = "POST";
      var async = true;
      var request = new XMLHttpRequest();
     
     
        request.onreadystatechange = function ()
        {
        var status = request.status; // HTTP response status, e.g., 200 for "200 OK"
        var data = request.responseText; // Returned data, e.g., an HTML document.
        output.innerHTML = "Status: " + status + "<br>" + data;
        }
       
      request.open(method,url , async);
      request.setRequestHeader("Content-Length", $parameters.zpl.length);
     
   // Actually sends the request to the server.
     
      request.send($parameters.zpl);
     
    //alert("success");

This works on one device that i have but when i try in the tablet or a samsung S6 in the same network it didnt. 

Hello Frederick.

Are you using a JSNode in a ClientAction to do this?

Also, you can try to troubleshoot and check for JS errors by connecting the device to your laptop. More info in the article Debug Screens and Logic

Thanks



César Afonso wrote:

Hello Frederick.

Are you using a JSNode in a ClientAction to do this?

Also, you can try to troubleshoot and check for JS errors by connecting the device to your laptop. More info in the article Debug Screens and Logic

Thanks



Hi César,

Yes, i have de JSNode inside a client action.

Solution

Hi Frederick,


I would say that you are most likely hitting an error because of Same Origin policies in your device browser. Different devices browsers handle these policies differently.

For example writing a header (that "Content-Length") in a cross domain request (like that one to a custom ip) is a change that requires a preflight check. Without this the request will most likelly succeed, but you won't be able to read the response (or it will even throw an error) if your printer does not implement the CORS protocol correctly.

I googled and found this blog post about http post printing and CORS. That post talks exactly about that issue.


Regards,
João Rosado

Solution

João Rosado wrote:

Hi Frederick,


I would say that you are most likely hitting an error because of Same Origin policies in your device browser. Different devices browsers handle these policies differently.

For example writing a header (that "Content-Length") in a cross domain request (like that one to a custom ip) is a change that requires a preflight check. Without this the request will most likelly succeed, but you won't be able to read the response (or it will even throw an error) if your printer does not implement the CORS protocol correctly.

I googled and found this blog post about http post printing and CORS. That post talks exactly about that issue.


Regards,
João Rosado

Hi João,

Thanks for the reply, i just realice that i'm using a device from the same family as the thermal printer, now i'm going to check the post that you recommended.


Best regarts.