Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    144
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Sending and Recieving XML via cURL

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

  • #2
    Regular Coder
    Join Date
    Apr 2007
    Posts
    144
    Thanks
    5
    Thanked 0 Times in 0 Posts


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •