Author Topic: UPS XML result with http headers  (Read 4862 times)

bachelorzdb

  • Beginner
  • *
  • Posts: 9
UPS XML result with http headers
« on: January 14, 2011, 05:05:14 am »
Hi All,
I'm using UPS as my shipping module,
and I find that vitruemart could not get shipping quotes from UPS in some cases.
 after some investigation, I found that the xml result from UPS contains http headers.so the xml parser consider the xml doc as an invalid xml doc.

and my solutions as following, I hope it may help some guys. ;D

administrator/components/com_virtuemart/classes/connectionTools.class.php
Line 130:
Code: [Select]
if( $urlParts['scheme'] == 'https') {
// No PEER certificate validation...as we don't have
// a certificate file for it to authenticate the host www.ups.com against!
curl_setopt($CR, CURLOPT_SSL_VERIFYPEER, 0);
//curl_setopt($CR, CURLOPT_SSLCERT , "/usr/locale/xxxx/clientcertificate.pem");
}
/*---------------- HACK START --------------------- */
            /*Don't return the headers*/
            curl_setopt($CR, CURLOPT_HEADER, false);
/*---------------- HACK END --------------------- */
$result = curl_exec( $CR );
$error = curl_error( $CR );
line 252:
Code: [Select]
  // $result = trim( $data ); // original
  // Remove Http header xml stream
  $result = preg_replace('/.*?\r\n\r\n(.*)/s', '$1', trim( $data ));

bachelorzdb

  • Beginner
  • *
  • Posts: 9
Re: UPS XML result with http headers
« Reply #1 on: January 20, 2011, 13:22:22 pm »
路过~~

cte2087

  • Beginner
  • *
  • Posts: 4
Re: UPS XML result with http headers
« Reply #2 on: January 26, 2011, 02:23:41 am »
Can you give me a better idea of where to place the second snippet of code? My line 252 is commented out as some author comments

bachelorzdb

  • Beginner
  • *
  • Posts: 9
Re: UPS XML result with http headers
« Reply #3 on: February 18, 2011, 10:59:10 am »
Code: [Select]
// If didnt get content-length, something is wrong, return false.
if ( trim($data) == '' ) {
$vmLogger->err('An error occured while communicating with the server '.$urlParts['host'].'. It didn\'t reply (correctly). Please try again later, thank you.' );
return false;
}
if(strpos($url, 'zip')) {
   $result = $data;
}     
else {
               // $result = trim( $data ); // original
               // Remove Http header xml stream
               $result = preg_replace('/.*?\r\n\r\n(.*)/s', '$1', trim( $data ));
}
if( is_resource($fileToSaveData )) {
fwrite($fileToSaveData, $result );
return true;
} else {
return $result;
}

Kalen

  • Beginner
  • *
  • Posts: 9
Re: UPS XML result with http headers
« Reply #4 on: August 17, 2011, 21:55:52 pm »
Nice

Just used the second hack, works great.