timeout
timeout

Reputation: 35

send and respond with curl

i want receive xml file via curl and respond back. website 'A' sends xml info to webiste 'B', website 'B' need to respond back to 'A'

i know how to do it through post array but can not do it with xml

website 'A' sends this

$xml_data ='<test_data>
      <one>
      <demo>123</demo>
      <demo2>456</demo2> 
      <Password>mypassword</Password>
      </one>
      </test_data>';


   $url = "http://www.domain.com/path/";

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

Website 'B' need to get this and check the data and in database then respond back with a message lets say

$xml_data ='<test_data>
      <one>
      <checked>success</checked>
      <demo>123</demo>
      <demo2>456</demo2> 
      <Password>mypassword</Password>
      </one>
      </test_data>';

Upvotes: 1

Views: 522

Answers (1)

samura
samura

Reputation: 4395

Try this:

<?php
  $xml_data ='<test_data>
      <one>
      <checked>success</checked>
      <demo>123</demo>
      <demo2>456</demo2> 
      <Password>mypassword</Password>
      </one>
      </test_data>';

  header('Content-type: text/xml');

  echo $xml_data;
?>

Upvotes: 1

Related Questions