What is the best way to post XML from a form using Curl.
I have a HTML Form and i post the data to a new php page and all the fields are collected. How do i collect these fields in XML Format.
I can process it from a xml file, how do i alter my current codeso it doesnt use a file , but builds it on the same page then sends it.
$filename = "data.xml";
$handle = fopen($filename, "r");
$XPost = fread($handle, filesize($filename));
fclose($handle);
$url = "http://test.com/webservicerequest.asmx";
$ch = curl_init(); // initialize curl handle
curl_setopt($ch, CURLOPT_VERBOSE, 1); // set url to post to
curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return into a variable
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HEADER, "http://test.com/webservicerequest/SubmitLead");
curl_setopt($ch, CURLOPT_TIMEOUT, 99999999); // times out after 4s
curl_setopt($ch, CURLOPT_POSTFIELDS, $XPost); // add POST fields
curl_setopt($ch, CURLOPT_POST, 1);
$result = curl_exec($ch); // run the whole process
if (empty($result)) {
// some kind of an error happened
die(curl_error($ch));
curl_close($ch); // close cURL handler
} else {
$info = curl_getinfo($ch);
curl_close($ch); // close cURL handler
if (empty($info['http_code'])) {
die("No HTTP code was returned");
} else {
// load the HTTP codes
$http_codes = parse_ini_file("response.inc");
// echo results
echo "The server responded:
";
echo $info['http_code'] . " " . $http_codes[$info['http_code']];
}
}
echo "</br>";
var_dump($result) ;