1

I'm setting up a little webservice (local LAN) to print some data on an Epson Thermal Printer with ePOS. They have great documentation about how to send the XML request from JavaScript, but my problem is I want the server to print the data from a database, so there is no javascript.

I need to "translate" this JavaScript to php where req is the request:

var xhr = new XMLHttpRequest();
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xhr.setRequestHeader('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT');
xhr.setRequestHeader('SOAPAction', '""');
xhr.onreadystatechange = function () {

   // Receive response document
   if (xhr.readyState == 4) {

      // Parse response document
      if (xhr.status == 200) {
         alert(xhr.responseXML.getElementsByTagName('response') [0].getAttribute('success'));
      }
      else {
         alert('Network error occured.');
      }
   }
};

xhr.send(req);

I already tried this one:

$opts = array('http' =>
    array(
        'method'  => 'POST',
        'header'  => ["Content-type: text/xml; charset=utf-8", "If-Modified-Since: Thu, 01 Jan 1970 00:00:00 GMT", "SOAPAction: ''"],
        'content' => $content
    )
);
# Create the context
$context = stream_context_create($opts);
# Get the response (you can use this for GET)
$result = file_get_contents($url, false, $context);

But seems not to work.

I will try with curl, but somehow I don't understand how to set the headers correctly and how to send the data...

Can someone help me?

Dominik
  • 115
  • 1
  • 1
  • 6
  • Maybe this link help you - https://stackoverflow.com/questions/2138527/php-curl-http-post-sample-code – Dmitry Nov 08 '19 at 14:10

0 Answers0