Sending and Recieving XML via cURL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cesarcesar
Forum Contributor
Posts: 111
Joined: Mon Oct 18, 2004 3:28 pm

Sending and Recieving XML via cURL

Post by cesarcesar »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm new to sending, receiving, and reading XML. I'm trying to send and receive XML data via cURL. I am using curl because it was so easy with just arrays. I am using the following code to generate the XML and the PHP script that is presently not working. It would be great if some great code god can explain whats wrong to me.

build_xml.php

Code: Select all

<?php
'<?xml version="1.0"?>'
$xml = "<member><name>name</name></member>";
echo $xml;
?>
Array Method - Works great with arrays. I tried with XML as $data, and it no work. Getting it working this way is preferred.

Code: Select all

<?php
exec("/usr/bin/curl -m 120 -d \"$xml\" http://www.example.com/index.php -L", $response);
// $response is null
?>
Alternate Method - This way is failing also.

Code: Select all

<?php 
$url = "build_xml.php";
$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
$result = curl_exec($ch); // run the whole process
echo $result; //contains response from server 
// NO RESPONSE RECEIVED
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

What is failing? The sending or receiving?

And where is the failure occurring?
cesarcesar
Forum Contributor
Posts: 111
Joined: Mon Oct 18, 2004 3:28 pm

Post by cesarcesar »

Post Reply