xml - php : get TNT Australia live shipping rates of all tnt shipping methods -


i want live rates of shipping methods of tnt australia between origin , delivery address.

like road express, overnight express, overnight payu satchel, 9:00 express, 10:00 express, etc.

i using below code.

function sendtotntserver( $xml ) {  $postdata = http_build_query(                    array(                      //for future reference                      //the xml_in= ( = ) appended                      //automatically php                     'xml_in' => $xml                     )         );  $opts = array('http' =>             array(                'method'  => 'post',                'header'  => 'content-type: application/x-www-form-urlencoded',                'content' => $postdata              )          );  $context  = stream_context_create( $opts ); $output = file_get_contents(         'http://www.tntexpress.com.au/expressconnect/pricing/getprice',         false,         $context       );       return $output; }  $xmlstring = "<?xml version=\"1.0\" encoding=\"utf-8\"?>                <pricerequest>                     <login>                         <company>username</company>                         <password>password</password>                         <appid>pc</appid>                     </login>                     <pricecheck>                         <rateid>rate1</rateid>                         <origincountry>au</origincountry>                         <origintownname>atherstone</origintownname>                         <originpostcode>2217</originpostcode>                         <origintowngroup/>                         <destcountry>au</destcountry>                         <desttownname>alicante</desttownname>                         <destpostcode>6009</destpostcode>                         <desttowngroup/>                         <contype>n</contype>                         <currency>aud</currency>                         <weight>18</weight>                         <volume>1</volume>                         <account/>                         <items>1</items>                   </pricecheck>              </pricerequest>";  $returnxml = sendtotntserver( $xmlstring ); echo $returnxml; 

but gives me message login details invalid.

our tnt account created on http://www.tntexpress.com.au/ link.

i using php server side language.

i got answer after lot of stuck , discussion tnt.

<?php  /**  *  submit xml tnt  *  server via stream instead  *  of curl.   *  *  @returns string (xml) **/  function sendtotntserver( $xml ) {  $username = username starting cit000  $password = ******  $senderaccount = *******   $postdata = http_build_query(                    array(                      'username' => $username,                      'password' => $password,                     'xmlrequest' => $xml                     )         );  $opts = array('http' =>             array(                'method'  => 'post',                'header'  => 'content-type: application/x-www-form-urlencoded',                'content' => $postdata              )          );  $context  = stream_context_create( $opts ); $output = file_get_contents(         'https://www.tntexpress.com.au/rtt/inputrequest.asp',         false,         $context       );       return $output; }  $xmlstring = "<?xml version='1.0'?> <enquiry xmlns='http://www.tntexpress.com.au'> <ratedtransittimeenquiry> <cutofftimeenquiry>   <collectionaddress>     <suburb>sydney</suburb>     <postcode>2000</postcode>     <state>nsw</state>   </collectionaddress>   <deliveryaddress>     <suburb>melbourne</suburb>     <postcode>3000</postcode>     <state>vic</state>   </deliveryaddress>   <shippingdate>2007-11-05</shippingdate>   <usercurrentlocaldatetime>     2007-11-05t10:00:00   </usercurrentlocaldatetime>   <dangerousgoods>     <dangerous>false</dangerous>   </dangerousgoods>   <packagelines packagetype='d'>     <packageline>       <numberofpackages>1</numberofpackages>       <dimensions unit='cm'>         <length>20</length>         <width>20</width>         <height>20</height>       </dimensions>       <weight unit='kg'>         <weight>1</weight>       </weight>     </packageline>   </packagelines> </cutofftimeenquiry> <termsofpayment>   <senderaccount>$senderaccount</senderaccount>   <payer>s</payer> </termsofpayment> </ratedtransittimeenquiry> </enquiry>";  $returnxml = sendtotntserver( $xmlstring ); echo $returnxml;  ?> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -