tags:

views:

70

answers:

2

I have a php page say test.php

Here i am creating an xml

$xmlVariable = <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<signupInfo>
<address>
      <address>1 Infinite Loop</address>
      <city>Cupertino</city>
      <state>CA</state>
      <zip>99999</zip>
    </address>

</signupInfo>

Now i need to send it to a destination(eg:https://destination.cm/fg)

How can i send this xml?

+1  A: 

With cURL

http://www.php.net/manual/en/ref.curl.php

$curl_handle = curl_init();
if (!$curl_handle) {
  die('fail to initialize');
}

curl_setopt($curl_handle, CURLOPT_TIMEOUT, 30);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 30);

//target URL setup
curl_setopt($curl_handle, CURLOPT_URL, 'https://destination.cm/fg');
//mime type setup, change if necessary
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, array("Content-Type: application/xml"));

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_FAILONERROR, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);

//here you assign the body of your request
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $xmlVariable);

$response = curl_exec($curl_handle);

if (curl_errno($curl_handle)) {
  die(curl_error($curl_handle));            
}

printf("Received :\n%s", $response);
Guillaume Bodi
Thanks for the detailed answer.Let me check with that
Linto P D
A: 

Maybe your xml data is not very long,but it's not suggested that you send data using this way.It refers to security problem.So use POST instead of get

forget this post,I get something wrong...sorry :(

T_t
How is post more secure than get?
Juan Pablo Califano
And who said anything about GET?
David Dorward
how can i use POST here, could you explain more?
Linto P D