Jump to content

Recommended Posts

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

<?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.

<?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.

<?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
?>

Link to comment
https://forums.phpfreaks.com/topic/63293-sending-and-recieving-xml-via-curl/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.