0

What do I have to do on the server page and how to receive this xml file? I'm stuck. The xml is fine, it is checked with simplexml_load_string.

 $var='caca';
 $login_xml ='<xml>'.
         '<action>log_in</action>'.
     '<parameters>'.
         '<username>'.$var.'</username>'.
     '<pass>abdef01</pass>'.
     '</parameters>'.
     '</xml>';

 $URL = "http://myurl.com/login.php/";


 $ch = curl_init($URL);
 curl_setopt($ch, CURLOPT_MUTE, 1);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
 curl_setopt($ch, CURLOPT_POSTFIELDS, "$login_xml");
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
 $output = curl_exec($ch);
 curl_close($ch);

Thank you for your time.

2 Answers2

2

Since the data is send as text/xml and not as url-encoded form-data, you can't use $_POST. You have to read the raw request from the php://input stream

$xml = file_get_contents('php://input');
Maxim Krizhanovsky
  • 26,265
  • 5
  • 59
  • 89
0

You have an error in your CURLOPT_POST_FIELDS: This option, must be an array:

...
$data = array('xml' => $login_xml);
...

And then:

...
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
...

This sends the value 'xml' as post field;

Hope this helps.

Yefb
  • 146
  • 8
  • When I print_r($_POST) on server script I still get an empty array. But thanks for your help. Improving incrementally:) – anna karenina May 21 '12 at 20:51