Re: Problems posting xml file with curl and php

From: Date: Tue, 18 Mar 2008 20:37:37 +0000
Subject: Re: Problems posting xml file with curl and php
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-271746@lists.php.net to get a copy of this message
I've actually tried that and it didn't work for the server I am sending it to. Is there a way to post just the xml without turning it into an array or is this the only way. Nathan Nobbe wrote:
On Tue, Mar 18, 2008 at 4:26 PM, michaelh613 <michael@yourcomputerconsultant.com <mailto:michael@yourcomputerconsultant.com>> wrote:
    I have created a XML string using PHP DOM.  However when I send it
    to a third
    party using curl it shows up as part of an array and cannot be
    read.  How
    should I be using curl to post a xml file.
    My code is below
    [code]
    <?php
    Require 'createxml.php';
    $Result = simplexml_load_string($result);
    $xmlResult= $Result->asXML();
    $ch= curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
    curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Accept: text/xml"));
    curl_setopt($ch, CURLOPT_URL, "http://testurl.com");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlResult);
    curl_setopt($ch, CURLOPT_POST,1);
    curl_exec($ch);
    [/code]
CURLOPT_POSTFIELDS must be specified as an array, therefore you will need to conjure up some identifier and place it your xml in an array as follows, curl_setopt($ch, CURLOPT_POSTFIELDS, array('xml' => $xmlResult)); -nathan


« previous php.general (#271746) next »