473,382 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Sending and Recieving XML via cURL

162 100+
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
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. '<?xml version="1.0"?>'
  3. $xml = "<member><name>name</name></member>";
  4. echo $xml;
  5. ?>
  6.  
Array Method - Works great with arrays. I tried with XML as $data, and it no work. Getting it working this way is preferred.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. exec("/usr/bin/curl -m 120 -d \"$xml\" http://www.example.com/index.php -L", $response);
  3. // $response is null
  4. ?>
  5.  
Alternate Method - This way is failing also.
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $url = "build_xml.php";
  3. $ch = curl_init();    // initialize curl handle
  4. curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
  5. curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
  6. curl_setopt($ch, CURLOPT_TIMEOUT, 4); // times out after 4s
  7. curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
  8. $result = curl_exec($ch); // run the whole process
  9. echo $result; //contains response from server 
  10. // NO RESPONSE RECEIVED
  11. ?>
  12.  
Aug 4 '07 #1
3 3998
pbmods
5,821 Expert 4TB
Heya, empiresolutions.

build_xml.php
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. '<?xml version="1.0"?>'
  3. $xml = "<member><name>name</name></member>";
  4. echo $xml;
  5. ?>
  6.  
In this code, you're not actually outputting the XML header. Is this intentional?

Perhaps you meant to do this instead:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $xml = '
  3. <?xml version="1.0" encoding="utf-8"?>
  4. <member>
  5.     <name>name</name>
  6. </member>';
  7.  
  8. return $xml;
  9. ?>
  10.  
Then in your main code:
Expand|Select|Wrap|Line Numbers
  1. $xml = require('build_xml.php');
  2.  
Aug 4 '07 #2
pbmods
5,821 Expert 4TB
Heya, empiresolutions.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Haluk Durmus | last post by:
Hello I checked out openssl,mm,apr,apr-util,apache 2,curl,libxml and php from cvs. php couse an ERROR I did the following steps:
17
by: Stefan Richter | last post by:
Hi, I would like to conect to a server by a SSL Conection, to send an SMS. The company that offers the SMS service provided some Code for a http connection, but not for a https connection. Here...
3
by: Chris Fortune | last post by:
# uname -a Linux stargate.mxc-online.net 2.4.20-021stab022.2.777-smp #1 SMP Wed Jul 28 17:12:37 MSD 2004 i686 i686 i386 GNU/Linux I recompiled PHP with mcrypt, openssl, and curl phpinfo():...
4
by: Edwin Rozie | last post by:
Hey can U help me with the following? I would like to send basic data (like a set of integers & strings) from one php function to another php function. Sounds easy, However, the functions are...
4
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes...
0
by: nfhm2k | last post by:
I've been trying to find a solution to this for quite some time now... I even took a look at existing scripts... Including this one......
9
by: Miro | last post by:
VB 2003 at the end of the code, this works great. bytCommand = Encoding.ASCII.GetBytes("testing hello send text") udpClient.Send(bytCommand, bytCommand.Length) and this recieves it Dim...
0
by: existatus | last post by:
In a form there are entries like this: <input type="text" name="first_name" size="24" /> <input type="text" name="last_name" size="24" /> <input type="hidden" name="must_have" value="12345" />...
6
by: lakmarket | last post by:
Hi, I am trying to send some querysting using cURL. This is the working API ...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.