Jump to content

help with posting to XML


glennnall

Recommended Posts

i'm doing a form that posts values to XML, and i don't know how.

 

can someone help me with a quick lesson in passing variables/XML data? i don't even know what question to ask, actually -

 

the XML format i've been given is:


<?xml version="1.0" encoding="UTF-8"?>
<lead>
    <innerNode></innerNode>
    <last_name>Smith</last_name>
    <first_name>John</first_name>
</lead>

 

and what i've come up with so far is this, but i don't even know if i'm on the right track:

 



$last_name = $_REQUEST['l_name'];
$first_name = $_REQUEST['f_name'];


$url = "http://url.com/leads";

$post_string = '<?xml version="1.0" encoding="UTF-8"?>
<lead>
    <innerNode></innerNode>
    <last_name>'.$last_name.'</last_name>
    <first_name>'.$first_name.'</first_name>
</lead>';


$header  = "POST HTTP/1.0 \r\n";
$header .= "Content-type: text/xml \r\n";
$header .= "Content-length: ".strlen($post_string)." \r\n";
$header .= "Content-transfer-encoding: text \r\n";
$header .= "Connection: close \r\n\r\n"; 
$header = $post_string;

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 4);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);

$data = curl_exec($ch); 

if(curl_errno($ch)) {
    print curl_error($ch);
} else {
echo "yay";
    curl_close($ch);
}

 

i'm being told "should return a response.xml with either a success or failure post status." which is confusing me

 

can someone help a bit?

 

thanks very much...

 

GN

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.