473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

xml-rpc+php+socket --> UPS online tool

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
http://www.keithdevens.com/software/xmlrpc/
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:443";
$location = "/ups.app/xml/AV";
$upsAccessLicenseNumber = "myAccessLiscenseNumber"; //
2BAADC11591CC248
$upsUserID = "myID";
$upsPassWord = "myPW";
$upsXpciVersion = "1.0001";
function XMLRPC4UPSAV_request($city, $state=NULL, $zip=NULL){

global $site, $location, $upsAccessLicenseNumber, $upsUserID,
$upsPassWord, $upsXpciVersion;

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

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

//Access Request
$accessData["AccessRequest"]["AccessLicenseNumber"] =
$upsAccessLicenseNumber;
$accessData["AccessRequest"]["UserId"] = $upsUserID;
$accessData["AccessRequest"]["Password"] = $upsPassWord;

$accessData = XML_serialize($accessData);

// Address Validation Request
$avData["AddressValidationRequest"]["Request"]["TransactionReference"]["CustomerContext"]
= "AV TEST";
$avData["AddressValidationRequest"]["Request"]["TransactionReference"]["XpciVersion"]
= $upsXpciVersion;
$avData["AddressValidationRequest"]["Request"]["RequestAction"] =
"AV";
$avData["AddressValidationRequest"]["Address"]["City"] = $city;

if(isset($state))$avData["AddressValidationRequest"]["Address"]["StateProvinceCode"]
= $state;
if(isset($zip))$avData["AddressValidationRequest"]["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($conn)){ $response .= fgets($conn, 1024); }
fclose($conn);

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

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

<body>
<?
print_r(XMLRPC4UPSAV_request("Little Ferry", "NJ"));
?>
</body>
</html>
Jul 17 '05 #1
0 3244

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: jason | last post by:
Hi Ray...a while ago you explained an elegant solution to enable me to CREATE and EDIT existing tables and queries inside my online access 2000 database.... could you provide refresher links on...
1
by: Wolfgang Keller | last post by:
Hello, just as an introduction: I'm not a developer by profession, I just need a solution for this within the scope of a single project... What I am looking for is basically a tool (usable for...
10
by: Jason Collins | last post by:
There are some Requests that occur that have a NULL UserAgent. Some of these are legitimate crawlers (e.g., Overture's crawler), and I'm attempting to adjust my <browserCaps> to correctly classify...
1
by: Clara Yeung | last post by:
I have captured some SOAP messages (using org.wsi.test.monitor.Monitor of the WSI test tool). When I try to analyze the messages with WSI test tool analyzer, the "message" artifact of the report...
0
by: yoshita | last post by:
Hi there! As i understand from the UPS rate and service guide I need to create an XML post to the UPS online tool server and get a response XML. Could anyone guide me with how to code in .net...
0
by: =?Utf-8?B?Sm9uYXRoYW4=?= | last post by:
Hi, we have a number of clients that range from corporates to single users. Currently our applications are written in MS Access. However the corporates are requesting that we migrate to dot Net and...
0
by: shapper | last post by:
Hello, I used an online tool to covert a VB.NET code I had to C# that I know use: <ConfigurationProperty("Google")_ Public ReadOnly Property Google() As ElementCollection Get Return...
4
by: Naga Prakash | last post by:
Hello All, I'm very much new to PERL scripting. I'm the admin for an online tool which has some Perl scripts. And i have a problem executing one of the script. I'm just writing a problematic code in...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.