How to read an xml file sent via http post

Discussion in 'PHP' started by michaelh613, Apr 2, 2008.

  1. #1
    I've tried a few solutions

    $xml = new SimpleXMLElement($_POST);


    This gives and error

    Fatal error: Uncaught exception 'Exception' with message 'SimpleXMLElement::__construct() expects parameter 1 to be string, array given' in C:\Inetpub\Sites\ACR\test.php:12 Stack trace: #0 C:\Inetpub\Sites\ACR\test.php(12): SimpleXMLElement->__construct(Array) #1 {main} thrown

    Fatal error: Call to undefined function simple_xml_loadstring() in

    Yet I know the function itself works because I have used it with curl when I have received a string back

    $reply = curl_exec($ch);
    $xml=simplexml_load_string($reply);


    So I assume my problem is my $_POST is a array and not a string. So my question is how to extract my xml from my post variable so I can read it correctly.
     
    michaelh613, Apr 2, 2008 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    yeah $_POST is an array so to access the variabl you should put the name of the variable ... so something like this :

    $_POST["NAME OF THE VARIABLE SENT"];
     
    commandos, Apr 2, 2008 IP
  3. michaelh613

    michaelh613 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    I have no control over what is sent because it comes from a third party.

    The issue is with xml there is no variable name like there is in a form.

    Compare it to sending a post with curl

    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlstr);

    If I try to read this post using a standard like

    foreach( $errors as $_POST => $value ){
    if( !isset(${$key}) ){ // Don't clobber existing values
    ${$key} = $value;
    }
    if ($debug == 1) {
    echo "<P>$key => $value<P>\n"; //testing
    }
    }

    I would get an error message

    Warning: Invalid argument supplied for foreach()
     
    michaelh613, Apr 2, 2008 IP
  4. michaelh613

    michaelh613 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    michaelh613, Apr 2, 2008 IP