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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

hmm okay i do some more researches and i will give it a try, thank you
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.
Why don't you update your post with that info... It's a little bit hard to read here in the comments...
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 <tag>val</tag> not only the val.
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 <pre> or <code> tag, then you will see all of the data...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.