Submit Form post as XML
Hi,
I'm trying to create a new shipping calculator for my Ecart store using InterParcel here in Australia. I have the API guide and have built the following code in accordance to their guide, however I don't get a response back from the server. Curl is Enabled on the host server and i receive the correct lines if i echo the results but no server response? Do i need to put the $post_string into an array. Example of the bad request is here:xml-form.php Use Suburb Sydney Postcode:2000
Any ideas?
My code looks like this
<?php
// Your post data
$post_city= $_POST['city'];
$post_postcode = $_POST['postcode'];
// Building your XML string
$strXML = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
$strXML .= '<Request>'."\n";
$strXML .= '<Authentication>'."\n";
$strXML .= '<UserID>test@test.com</UserID>'."\n";
$strXML .= '<Password>pass123456</Password>'."\n";
$strXML .= '<Version>1.0</Version>'."\n";
$strXML .= '</Authentication>'."\n";
$strXML .= '<RequestType>Rates</RequestType>'."\n";
$strXML .= '<ShowAvailability>N</ShowAvailability>'."\n";
$strXML .= '<Shipment>'."\n";
$strXML .= '<Collection>'."\n";
$strXML .= '<City>Cranbourne</City>'."\n";
$strXML .= '<Country>Australia</Country>'."\n";
$strXML .= '<Postcode>3977</Postcode>'."\n";
$strXML .= '</Collection>'."\n";
$strXML .= '<Delivery>'."\n";
$strXML .= '<City>'.$post_city.'</City>'."\n";
$strXML .= '<Country>Australia</Country>'."\n";
$strXML .= '<Postcode>'.$post_postcode.'</Postcode>'."\n";
$strXML .= '</Delivery>'."\n";
$strXML .= '<Package>'."\n";
$strXML .= '<Weight>4</Weight>'."\n";
$strXML .= '<Length>43</Length>'."\n";
$strXML .= '<Width>46</Width>'."\n";
$strXML .= '<Height>66</Height>'."\n";
$strXML .= '</Package>'."\n";
$strXML .= '</Shipment>'."\n";
$strXML .= '</Request>'."\n";
$url = "https://www.interparcel.com.au/api/xml/rates.php";
$post_string = $strXML;
$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
curl_close($ch);
?>