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 4 of 4
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    put failed with curl and simplexml

    I am using curl to put an update to an xml file which is made into an simpleXML object then I use asXML() before putting the file to curl.

    I have a three function setup for this:
    >>get with a curl (works fine)
    >>process data with simpleXML (maybe causing problems)
    >>putting info with curl (works fine when used on other simpleXML calls)

    I should note that the get and put with curl functions are being reused and succeed in all other cases I use it.

    I just one unique function for this particular simpleXML call which does the processing. I am currently getting a 400 error when I try to put with curl (this is the most info I have at this point)

    Here is my unique simpleXML process function:
    PHP Code:
    function processData($result$value)
    {
        
        
    $xml = new SimpleXMLElement($result);
        
    $newXML =     '<&quest;xml version="1.0" encoding="UTF-8" standalone="yes"&quest;>
            <subscription xmlns="http://domain.com">
                <status>'
    .$xml->status.'</status>
                <data>'
    .$value.'</data>
                <id>'
    .$xml->id.'</id>
                <card>
                    <last-four>'
    .$xml->card->{"last-four"}.'</last-four>
                    <type>'
    .$xml->card->type.'</type>
                </card>
                <charge>
                    <currency>'
    .$xml->{"charge"}->currency.'</currency>
                    <amount>9.99</amount>
                </charge>
                <charge-frequency>'
    .$xml->{"charge-frequency"}.'</charge-frequency>
                <date>'
    .$xml->date.'</date>
                <auto-renew>'
    .$xml->{"auto-renew"}.'</auto-renew>
                <last-charge-result>
                    <result-code>'
    .$xml->{"last-charge-result"}->{"result-code"}.'</result-code>
                </last-charge-result>
            </subscription>'
    ;
        
        
    $newSimpleXML = new SimpleXMLElement($newXML);
        
        
    $newSimpleXML->data $value;
        
    $newXML $newSimpleXML->asXML();
        echo 
    '$value is: "'.$value.'"<br />';
        echo 
    'new status is: '.$newSimpleXML->data.'<br />';
        echo 
    'The data was: '.$xml->data;

        return 
    $newXML;


    the $result is derived from the get curl function, I have checked the output it is getting all the info I need





    I appreciate any help in the matter
    Last edited by surreal5335; 06-19-2012 at 07:09 PM.

  • #2
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Why the &quest; entities? Why not use a simple question mark? Have you tried removing the XML prolog entirely?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog

  • #3
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    I out the &quest entities in so the [PHP] would not get thrown off and would continue reading the rest of the code as php.

    I have tried without the prolog still I get the same result.

    I also have simplified it down to using poster for firefox, to get a simplified result, but still I dont get anything good. Just a 404 error

  • #4
    Moderator
    Join Date
    May 2002
    Location
    Hayward, CA
    Posts
    1,461
    Thanks
    1
    Thanked 23 Times in 21 Posts
    Ah, yes, short_open_tags... I'd forgotten about that. (That's what causes <?xml ?> to be read as PHP code.)

    We might need a little bit more code - specifically, how you're calling processData(). Also, are you really using HTTP PUT or HTTP POST?
    "The first step to confirming there is a bug in someone else's work is confirming there are no bugs in your own."
    June 30, 2001
    author, Verbosio prototype XML Editor
    author, JavaScript Developer's Dictionary
    https://alexvincent.us/blog


  •  

    Posting Permissions

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