3

I have this code where I send data in an XML file via cURL to a press office. Now I want a feedback from the press that my orders are confirmed or done. I would like to have that in an XML file as well. I know how I send file via curl, now I would like to know how do i receive them so i can read out the data. Any suggestions are welcome.

this is how i send my XML:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $incomm_prod_server);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_POSTFIELDS, str_replace('{voucher_code}', $voucher_code, $xml_data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: close'));

So this is what i do on the ither side to get the XML:

  $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
    $result_xml = simplexml_load_string(curl_exec($ch));

But i get bool(false) as result back, so there is no xml sent?

EDIT: I can access the data like this:

  if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
        $postText = file_get_contents('php://input');
    }
    die(var_dump($postText));

I edit one last time, maybe it will help others, i access now my xml this way:

            if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){
            $postText = file_get_contents('php://input');
        }
        $xml = new SimpleXMLElement($postText);
        $packing_number = $xml->xpath('/feedback/packing_number');
        $packing_status = $xml->xpath('/feedback/packing_status');

this will give you an array back, you can access it like:

$packing_number[0]

or just loop trough it.

Barta Tamás
  • 889
  • 4
  • 15
  • 36

1 Answers1

2

Ok so the code you posted above doesn't really send the XML file. All it does is place the content of that XML file into a $_POST variable attached to the request.

To receive data (on the other side), all you have to do is take a look into the $_POST variable and your XML data should be there. You'd setup a script and data would be posted to it (possibly using the same method you are using above), and the content will be accessible to you.

Lix
  • 47,311
  • 12
  • 103
  • 131
  • 1
    hmm okay i do some more researches and i will give it a try, thank you – Barta Tamás Aug 20 '12 at 07:42
  • i try to do this on the other side: `$ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $result_xml = simplexml_load_string(curl_exec($ch)); curl_close($ch); die(var_dump($result_xml));` but i get bool(false) back. Not sure how to access the xml there. – Barta Tamás Aug 20 '12 at 08:44
  • 1
    Why don't you update your post with that info... It's a little bit hard to read here in the comments... – Lix Aug 20 '12 at 08:45
  • may i ask one more thing. I can access now the xml, but only the values. I would like to have the full xml file. Like val not only the val. – Barta Tamás Aug 20 '12 at 09:19
  • 1
    They are still there - the problem is that your browser is thinking that the tags are HTML tags. If you echo the contents into a `
    ` or `` tag, then you will see all of the data...
    – Lix Aug 20 '12 at 09:26