Hi,

I am trying to make a php script to calculate the shiping charge
automatically by communicating to UPS online tool.

In order to do that, I used:
1. XML-RPC implemented by Keith Devens

2. PHP Version 4.3.3 w/ '--with-openssl'
3. The code below is for testing to see if I can communicate to UPS;
but no luck.
4. looks like the code successfully open the socket and send xml to
UPS.
5. but I dont' get anything back or retreiving the response is
invalid?
6. here is my code
7. Please somebody fix me.

<?php
/* Include the library */
include ( "kd_xmlrpc. php" );

/* Define variables to find the rpc server script */
$site = "www.ups.com:44 3";
$location = "/ups.app/xml/AV";
$upsAccessLicen seNumber = "myAccessLiscen seNumber"; //
2BAADC11591CC24 8
$upsUserID = "myID";
$upsPassWord = "myPW";
$upsXpciVersion = "1.0001";


function XMLRPC4UPSAV_re quest($city, $state=NULL, $zip=NULL){

global $site, $location, $upsAccessLicen seNumber, $upsUserID,
$upsPassWord, $upsXpciVersion ;

list($site, $port) = explode(':', $site);
if(!is_numeric( $port)){$port = 80;}

echo $site . "<br>" . $port . "<p>";

//Access Request
$accessData["AccessRequ est"]["AccessLicenseN umber"] =
$upsAccessLicen seNumber;
$accessData["AccessRequ est"]["UserId"] = $upsUserID;
$accessData["AccessRequ est"]["Password"] = $upsPassWord;

$accessData = XML_serialize($ accessData);

// Address Validation Request
$avData["AddressValidat ionRequest"]["Request"]["TransactionRef erence"]["CustomerContex t"]
= "AV TEST";
$avData["AddressValidat ionRequest"]["Request"]["TransactionRef erence"]["XpciVersio n"]
= $upsXpciVersion ;
$avData["AddressValidat ionRequest"]["Request"]["RequestAct ion"] =
"AV";
$avData["AddressValidat ionRequest"]["Address"]["City"] = $city;

if(isset($state ))$avData["AddressValidat ionRequest"]["Address"]["StateProvinceC ode"]
= $state;
if(isset($zip)) $avData["AddressValidat ionRequest"]["Address"]["PostalCode "]
= $zip;

$avData = XML_serialize($ avData);

// combine Access Request & AV Request
$data = $accessData . $avData;

$conn = fsockopen ($site, $port); #open the connection

if(!$conn){ #if the connection was not opened successfully
echo "Failed";
}else{
$headers =
"POST $location HTTP/1.0\r\n" .
"Content-Type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($data) . "\r\n\r\n";

fputs($conn, $headers);
fputs($conn, $data);

$response = "";
while(!feof($co nn)){ $response .= fgets($conn, 1024); }
fclose($conn);

#strip headers off of response
$data = XML_unserialize (substr($respon se, strpos($respons e,
"\r\n\r\n")+4)) ;

return $data;
}
}
?>
<html>
<head>
<title> UPS Address Validator</title>
<meta name="Generator " content="EditPl us">
<meta name="Author" content="Jason" >
<meta name="Keywords" content="XML RPC">
<meta name="Descripti on" content="UPS AV">
</head>

<body>
<?
print_r(XMLRPC4 UPSAV_request(" Little Ferry", "NJ"));
?>
</body>
</html>