Thank you all, I have solved this and wrote my own answer on this question down below. Thank you all for trying
I have a simple (I hope) question as I am a complete newbie.
So I have 2 php files output.php
and input.php
.
output.php
is sending an XML to input.php
via cURL like so:
$myXML = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$myXML .= '<request>
<message>Hello StackOverflow</message>
<params>
<name>John</name>
<lname>Smith</lname>
</params>
</request>';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'http://localhost/curltest/input.php');
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $myXML);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array(
'Content-type: text/xml; charset=UTF-8',
'Expect: '
)
);
$curl_response= curl_exec($curl);
Currently the contents of input.php
look like this
<?php
// Yes, this is all
The problem is I don't know at all how to get and parse the XML data in input.php
and take data out of that XML for use in my input.php
script.
$_POST
is an empty array in input.php
, but the XML surely reaches input.php
because readfile('php://input');
inside of input.php
gives out the received XML.
I have read about DOMElement
but it was kind of unclear to me how to use it in my specific case. I also did a search on Google and in SO also, but didn't succeed in finding exactly what I need.
If someone could tell me how exactly is this done it would be great. Or at least point me in the right direction, I'm at a loss here.
P.S. I can't change anything in output.php
. And I will gladly provide any additional information if needed.