CURL and XML request

Discussion in 'PHP' started by samirkumardas, Jul 20, 2008.

  1. #1
    This is XML request using CURL

    <?php
    
    $url = "http://localhost/members/mailbiz_external.php";
    $request = <<<XML
    <?xml version="1.0" encoding="UTF-8"?>
    
    	<address>
                  <userid>333</userid> <!-- nur Zahlen -->
                  <salutation>Herr</salutation>
                  <firstname>Max</firstname>
                  <lastname>Mustermann</lastname>
                  <company>beispiel</company>
                  <street>Somewhere. 296</street>
                  <postalcode>12345</postalcode>
                  <city>Anywhere</city>
                  <country>Deutschland</country>
               </address>
    XML;
    
           $ch = curl_init();
    
    	curl_setopt($ch, CURLOPT_URL, $url);
    	curl_setopt($ch, CURLOPT_HEADER, false); 
    	curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    	curl_setopt($ch, CURLOPT_POST, true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
    	
    	$xml = curl_exec($ch);
    
    	echo $xml;
    
    curl_close($ch);
    ?>
    PHP:

    And the mailbiz_external.php page look like,
    <?
    print_r($_POST)
    ?>
    
    PHP:
    This gives result of array. But My problem I cant assign this array element (the xml) into a variable. I am not sure how can I access the variable so that I get the xml to proceed.

    I have tried $xml=$_POST[0]; but not work. Pls help
     
    samirkumardas, Jul 20, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    $request = urlencode($request);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "xml={$request}");
    
    PHP:
    ... you have to specify a name for the XML data.
     
    nico_swd, Jul 21, 2008 IP