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
https://forums.phpfreaks.com/topic/211961-help-with-posting-to-xml/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.